Hi,
I'm facing one issue and I really do not know where could the problem.
It's once again (as I read few other posts in the forum, nothing new) related to persisting order of columns in GridView. My problem happens only when the columns get reordered by drag-n-drop. When I add and or remove columns (this is done programatically in my view's code-behind) and try to persists Grid's state, everything works well. Unless I reorder their sequence.
It's worth mentioning that I'm persisting the state in my filesystem so that I could restore it later. Solution with IsolatedStorageProvider is not well suited for me. But I do not think that this should be any issue.Storage happens everytime the button 'Save layout' is being clicked.
I have created sample video that shows what I'm trying to say maybe even more expressively. Look here.I have created sample video that shows what I'm trying to say maybe even more expressively. Look here - https://drive.google.com/file/d/0B0cxhvgqPibkNHhyUzM1TVVHOVU/view
I have implemented my version of ICustomPropertyProvider, but it's almost identical to the one provided in WPF Control Examples. See here:
public class GridViewCustomPropertyProvider : ICustomPropertyProvider
{
private const string _columnsProperty = "Columns";
private const string _sortDescriptorsProperty = "SortDescriptors";
public CustomPropertyInfo[] GetCustomProperties()
{
return new CustomPropertyInfo[]
{
new CustomPropertyInfo(_columnsProperty, typeof(List<ColumnProxy>)),
new CustomPropertyInfo(_sortDescriptorsProperty, typeof(List<SortDescriptorProxy>)),
};
}
public void InitializeObject(object context)
{
if (context is RadGridView)
{
RadGridView gridView = context as RadGridView;
//gridView.Columns.Clear();
gridView.SortDescriptors.Clear();
foreach (GridViewColumn gridViewColumn in gridView.Columns)
{
gridViewColumn.ClearFilters();
}
}
}
public object InitializeValue(CustomPropertyInfo customPropertyInfo, object context)
{
return null;
}
public void RestoreValue(CustomPropertyInfo customPropertyInfo, object context, object value)
{
RadGridView gridView = context as RadGridView;
switch (customPropertyInfo.Name)
{
case _sortDescriptorsProperty:
gridView.SortDescriptors.SuspendNotifications();
gridView.SortDescriptors.Clear();
List<SortDescriptorProxy> proxies = value as List<SortDescriptorProxy>;
foreach (SortDescriptorProxy proxy in proxies)
{
GridViewColumn column = gridView.Columns[proxy.ColumnName];
gridView.SortDescriptors.Add(new ColumnSortDescriptor(){Column = column, SortDirection = proxy.SortDirection});
}
gridView.SortDescriptors.ResumeNotifications();
break;
default:
var columnProxies = value as List<ColumnProxy>;
//var orderedColumns = columnProxies.OrderBy(x => x.DisplayIndex);
foreach (ColumnProxy columnProxy in columnProxies)
{
GridViewColumn gridColumn = gridView.Columns[columnProxy.UniqueName];
gridColumn.DisplayIndex = columnProxy.DisplayIndex;
gridColumn.Header = "blabhalbl" + columnProxy.Header;
gridColumn.Width = columnProxy.Width;
//gridView.Columns.Add(gridColumn);
}
break;
}
}
public object ProvideValue(CustomPropertyInfo customPropertyInfo, object context)
{
RadGridView gridView = context as RadGridView;
var orderedColuns = OrderedColumns(gridView);
switch (customPropertyInfo.Name)
{
case _sortDescriptorsProperty:
{
List<SortDescriptorProxy> sortDescriptorProxies = new List<SortDescriptorProxy>();
foreach (ColumnSortDescriptor descriptor in gridView.SortDescriptors)
{
sortDescriptorProxies.Add(new SortDescriptorProxy()
{
ColumnName = descriptor.Column.UniqueName,
SortDirection = descriptor.SortDirection,
});
}
return sortDescriptorProxies;
}
default:
var columns = new List<ColumnProxy>();
foreach (GridViewColumn column in orderedColuns.OrderBy(x => x.DisplayIndex))
{
columns.Add(new ColumnProxy()
{
UniqueName = column.UniqueName,
Header = column.Header.ToString() + "someother",
DisplayIndex = column.DisplayIndex,
Width = column.Width
});
}
return columns;
}
}
private static List<GridViewColumn> OrderedColumns(RadGridView gridView)
{
var orderedList = new List<GridViewColumn>();
for (int i = 0; i < gridView.Columns.Count; i++)
{
orderedList.Add(gridView.Columns[i]);
}
return orderedList;
}
}
Thanks in advance for any piece of advice,
Erik