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

Save / Load settings

2 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Adam Marshall
Top achievements
Rank 1
Adam Marshall asked on 21 Apr 2010, 05:06 AM
Hi,

I have been using the save/load layout settings for a while. I noticed that the Display Index is now being saved in the Q1 2010 which is great!

However, I have just ran into a problem where my value converter wasn't being called when the the save/load was enabled.

I then also noticed that the DataFormatString wasn't being saved, and so wasn't being loaded either, meaning my date columns weren't formatted.

I have modified the LoadState code slightly, so that it doesn't clear the GridView Columns and re-add them, but just sets the values from the saved ColumnSetting collection.

   public virtual void LoadState()  
        {  
            try 
            {  
                Settings.Reload();  
            }  
            catch 
            {  
                Settings.Reset();  
            }  
 
            if (this.grid != null)  
            {  
                grid.FrozenColumnCount = Settings.FrozenColumnCount;  
 
                if (Settings.ColumnSettings.Count > 0)  
                {  
                    foreach (GridViewDataColumn column in grid.Columns)  
                    {  
       
                        ColumnSetting setting = Settings.ColumnSettings.FirstOrDefault<ColumnSetting>(x => x.UniqueName == column.UniqueName);  
 
                        if (setting != null)  
                        {  
                            column.IsVisible = setting.IsVisible;  
                            column.DisplayIndex = setting.DisplayIndex;  
 
                            if (setting.Width != null)  
                            {  
                                column.Width = new GridViewLength(setting.Width.Value);  
                            }  
 
                        }                       
                    }           
                }  
...  
 


This is working fine for my needs currently, but it would be good to have the DataFormatString and the value converter binding saved and working correctly.

(Please let me know if what I have done isn't a good solution as I wasn't sure the reasoning behind clearing all the built GridView Columns and readding them. )

Thanks,

A Marshall

2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 22 Apr 2010, 08:21 AM
Hi Adam,

Indeed your approach will work as excepted - it's just a different approach. You can extend our example and save more column settings in the same way including DataFormatString.

Let me know if you have any question and/or problem - I'll gladly help you.

All the best,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Adam Marshall
Top achievements
Rank 1
answered on 22 Apr 2010, 08:46 PM
Hey,

Thanks for the reply.

I did intially extend the example as you suggest, but ran into the issue where I wanted to change the DataFormatString after a grid's settings had already being saved. As the columns themselves are being loaded from the saved settings, it meant that once a save has occured, any changes made in the xaml column definitions don't get used (I dont use AutoGenerateColumns) . Resetting the settings class obviously will workaround this, but isn't very good for my client's to have their grid settings reset after an upgrade.

I don't really have any questions, it's more of an observation that the approach the example takes may/can have some issues later on.

Thanks!

A Marshall
Tags
GridView
Asked by
Adam Marshall
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Adam Marshall
Top achievements
Rank 1
Share this question
or