public virtual void SaveState(string fileName) { Settings.Reset(); if (grid != null) { if (grid.Columns != null) { Settings.ColumnSettings.Clear(); foreach (GridViewColumn column in grid.Columns) { if (column is GridViewDataColumn) { GridViewDataColumn dataColumn = (GridViewDataColumn)column; ColumnSetting setting = new ColumnSetting(); setting.PropertyName = dataColumn.DataMemberBinding.Path.Path; setting.UniqueName = dataColumn.UniqueName; setting.Header = dataColumn.Header; setting.Width = dataColumn.ActualWidth; setting.DisplayIndex = dataColumn.DisplayIndex; Settings.ColumnSettings.Add(setting); } } } //if (grid.FilterDescriptors != null) //{ // Settings.FilterSettings.Clear(); // foreach (IColumnFilterDescriptor cfd in grid.FilterDescriptors.OfType<IColumnFilterDescriptor>()) // { // FilterSetting setting = new FilterSetting(); // if (!(cfd.FieldFilter.Filter1.Value == FilterDescriptor.UnsetValue)) { // setting.Filter1 = new Telerik.Windows.Data.FilterDescriptor(); // setting.Filter1.Member = cfd.FieldFilter.Filter1.Member; // setting.Filter1.Operator = cfd.FieldFilter.Filter1.Operator; // setting.Filter1.Value = cfd.FieldFilter.Filter1.Value; // setting.Filter1.MemberType = null; // } // if (!(cfd.FieldFilter.Filter2.Value == FilterDescriptor.UnsetValue)) { // setting.Filter2 = new Telerik.Windows.Data.FilterDescriptor(); // setting.Filter2.Member = cfd.FieldFilter.Filter2.Member; // setting.Filter2.Operator = cfd.FieldFilter.Filter2.Operator; // setting.Filter2.Value = cfd.FieldFilter.Filter2.Value; // setting.Filter2.MemberType = null; // } // foreach (Telerik.Windows.Data.FilterDescriptor fd in cfd.DistinctFilter.FilterDescriptors.OfType<Telerik.Windows.Data.FilterDescriptor>()) { // if (fd.Value == FilterDescriptor.UnsetValue) { // continue; // } // Telerik.Windows.Data.FilterDescriptor newFd = new Telerik.Windows.Data.FilterDescriptor(); // newFd.Member = fd.Member; // newFd.Operator = fd.Operator; // newFd.Value = fd.Value; // newFd.MemberType = null; // setting.SelectedDistinctValues.Add(newFd); // } // setting.PropertyName = cfd.Column.DataMemberBinding.Path.Path; // Settings.FilterSettings.Add(setting); // } //} if (grid.SortDescriptors != null) { Settings.SortSettings.Clear(); foreach (var d in grid.SortDescriptors) { SortSetting setting = new SortSetting(); if (d is ColumnSortDescriptor) { var dg = d as ColumnSortDescriptor; setting.PropertyName = dg.Column.SortMemberPath ?? dg.Column.UniqueName; } else { setting.PropertyName = (d as SortDescriptor).Member; } setting.SortDirection = d.SortDirection; Settings.SortSettings.Add(setting); } } if (grid.GroupDescriptors != null) { Settings.GroupSettings.Clear(); foreach (var d in grid.GroupDescriptors) { GroupSetting setting = new GroupSetting(); if (d is ColumnGroupDescriptor) { var gd = d as ColumnGroupDescriptor; setting.PropertyName = gd.Column.GroupMemberPath ?? gd.Column.UniqueName; setting.SortDirection = gd.SortDirection; setting.DisplayContent = gd.DisplayContent; } else { var gd = d as GroupDescriptor; setting.PropertyName = gd.Member; setting.SortDirection = gd.SortDirection; setting.DisplayContent = gd.DisplayContent; } Settings.GroupSettings.Add(setting); } } Settings.FrozenColumnCount = grid.FrozenColumnCount; } Settings.Save(fileName); }
public void LoadStateCore() { if (this.grid != null) { grid.FrozenColumnCount = Settings.FrozenColumnCount; if (Settings.ColumnSettings.Count > 0) { foreach (ColumnSetting setting in Settings.ColumnSettings) { ColumnSetting currentSetting = setting; GridViewDataColumn column = (from c in grid.Columns.OfType <GridViewDataColumn>() where c.UniqueName == currentSetting.UniqueName select c).FirstOrDefault(); if (column != null) { if (currentSetting.DisplayIndex != null && currentSetting.DisplayIndex.Value < grid.Columns.Count) { column.DisplayIndex = currentSetting.DisplayIndex.Value; } if (setting.Width != null) { column.Width = new GridViewLength(setting.Width.Value); } } } } using (grid.DeferRefresh()) { if (Settings.SortSettings.Count > 0) { grid.SortDescriptors.Clear(); foreach (SortSetting setting in Settings.SortSettings) { Telerik.Windows.Data.SortDescriptor d = new Telerik.Windows.Data.SortDescriptor(); d.Member = setting.PropertyName; d.SortDirection = setting.SortDirection; grid.SortDescriptors.Add(d); } } if (Settings.GroupSettings.Count > 0) { grid.GroupDescriptors.Clear(); foreach (GroupSetting setting in Settings.GroupSettings) { Telerik.Windows.Data.GroupDescriptor d = new Telerik.Windows.Data.GroupDescriptor(); d.Member = setting.PropertyName; d.SortDirection = setting.SortDirection; d.DisplayContent = setting.DisplayContent; grid.GroupDescriptors.Add(d); } } if (Settings.FilterSettings.Count > 0) { foreach (FilterSetting setting in Settings.FilterSettings) { FilterSetting currentSetting = setting; GridViewDataColumn matchingColumn = (from column in grid.Columns.OfType <GridViewDataColumn>() where column.DataMemberBinding.Path.Path == currentSetting.PropertyName select column).FirstOrDefault(); //if (matchingColumn != null) { // ColumnFilterDescriptor cfd = new ColumnFilterDescriptor(matchingColumn); // if (setting.Filter1 != null) { // cfd.FieldFilter.Filter1.Member = setting.Filter1.Member; // cfd.FieldFilter.Filter1.Operator = setting.Filter1.Operator; // cfd.FieldFilter.Filter1.Value = setting.Filter1.Value; // } // if (setting.Filter2 != null) { // cfd.FieldFilter.Filter2.Member = setting.Filter2.Member; // cfd.FieldFilter.Filter2.Operator = setting.Filter2.Operator; // cfd.FieldFilter.Filter2.Value = setting.Filter2.Value; // } // foreach (Telerik.Windows.Data.FilterDescriptor descriptor in setting.SelectedDistinctValues) { // cfd.DistinctFilter.FilterDescriptors.Add(descriptor); // } // this.grid.FilterDescriptors.Add(cfd); //} } } } } }