How to reset saved sort and column settings of the Silverlight datagrid

The LightSwitch Silverlight client has many nice features that you get for free.

One of these features is that it automatically saves Sort and Column user customizations on the datagrids. When a user sorts, resizes or reorders the columns of a datagrid, these customizations are stored in the IsolatedApplicationStorage.

For some cases, this feature isn’t that handy. If you have a query with an advanced order, you don’t want the client to remember any sort customizations. Luckily you can easily reset these settings by deleting these IsolatedApplicationStorage settings.

Example:
On initialize, delete all saved Sort and Column settings

partial void Application_Initialize()

{

    IsolatedStorageSettings appSettings = IsolatedStorageSettings.ApplicationSettings;

    var sortAndColumnSettings = appSettings.Where(

            setting => setting.Key.Contains("SortSettings") || setting.Key.Contains("ColumnSettings")).ToList();

    foreach (var setting in sortAndColumnSettings)

    {

        appSettings.Remove(setting.Key);

    }

}

If you want to do this more precise, this is the pattern of the Key names:

Column settings: Screen.DataGridControl.ColumnSettings
Sort settings: Screen.QueryName.SortSettings

Enjoy!
Michiel

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s