This is a migrated thread and some comments may be shown as answers.

[Solved] RadGridViewSettings changes

0 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcus
Top achievements
Rank 1
Marcus asked on 11 May 2009, 06:30 PM
I thought I'd post a few changes I've made to the RadGridViewSettings.cs file that is part of the "Save and Load grid settings" example. The LoadState() function doesn't allow binding as the columns are cleared. I'm sure this could be added, but all I needed was the width. Here's my modified code that finds existing columns instead of creating them. You must have the UniqueName field set for each column:

if (Settings.ColumnSettings.Count > 0) 
                { 
                    //grid.AutoGenerateColumns = false; 
                    //grid.Columns.Clear(); 
 
                    //foreach (ColumnSetting setting in Settings.ColumnSettings) 
                    //{ 
                    //    GridViewDataColumn column = new GridViewDataColumn(); 
                    //    column.UniqueName = setting.UniqueName; 
                    //    column.HeaderText = setting.HeaderText; 
                    //    if (setting.Width != null) 
                    //    { 
                    //        column.Width = new GridLength(setting.Width.Value); 
                    //    } 
 
                    //    grid.Columns.Add(column); 
                    //} 
 
                    foreach (ColumnSetting setting in Settings.ColumnSettings) 
                    { 
                        GridViewDataColumn column = (GridViewDataColumn)grid.Columns[setting.UniqueName]; 
                        if (setting.Width != null
                        { 
                            column.Width = new GridLength(setting.Width.Value); 
                        } 
                    } 
                } 

Also, in the SaveState() function, it seems the following change is needed to save the column width. In the LINQ query that declares the "cell" property, change the where clause from

where c.Column.UniqueName == setting.PropertyName 

to

where c.Column.UniqueName == setting.UniqueName 



Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Share this question
or