I have a Datagrid whose column properties had to be saved automatically when changed. I am using ISOLATED STORAGE Settings to achieve this. As of now I am storing the DISPLAY INDEX property of the DataGrid Column.
In my code behind I am trying to push the settings along with the DataGridName as follows
List<GridColumnSettings> settings = new List<GridColumnSettings>();
for (int index = 0; index < dcDataGrid.Columns.Count; index++)
{
DataGridColumn column = dcDataGrid.Columns[index];
SettingsViewModel.GridColumnSettings setting = new GridColumnSettings(column.DisplayIndex, index);
settings.Add(setting);
}
**SendTemplatesSettingsViewModel.SaveSettings(settings, "dcBrowserDataGrid")**
The SaveSettings method looks liks this
public class SendTemplatesSettingsViewModel
{
public class GridColumnSettings
{
public int Index { get; set; } //Managing the column ordering of the DataGrid
public int DisplayIndex { get; set; } //Store the Index/order of the column in the underlying datasource/ViewModel.
public GridColumnSettings(int columnIndex, int displayIndex)
{
this.DisplayIndex = columnIndex;
this.Index = displayIndex;
}
}
public void SaveSettings(List<SendTemplatesSettingsViewModel.GridColumnSettings> settings, string gridName)
{
mySettings.SetSetting<List<GridColumnSettings>>(gridName, settings);
}
The SetSettings method is just instantiating the ISOLATED Storage and adding the values.
I would also like to store the Sorting order of the columns, but I am not able to find the right property to do so. Hope anyone can help. Thanks in advance.
I would use a collection view source as the data grid source then read/write to the SortDescriptions property: http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource(v=vs.110).aspx