Hi!
I need to store some view info for my grid. So I use
grid1.DisplayLayout.SaveAsXml(stream, PropertyCategories.All);
But I realized that my ValueLists can be changed between store and load. Can I save my grid without ValueLists so they got refreshed automatically during Loading?
Mila.
Hi Mila,
I'm pretty sure that one of the PropertyCategories is ValueLists. So you can exclude these from the saving and loading easily enough by just removing the flag.
Another option is to simply load the layout before you assign your ValueLists to the grid.
The problem is: if I exclude ValueLists flag from PropertyCategories then ValueLists didn't saved. But after loading view from XML my ValueLists are all cleared - no ValueLists at all so I should load ValueLists again.
I have a lot of ValueLists loading from DB and it takes some time. If user adds new value to ValueList then I just update my ValueList and that's all. I am not asking DB and not reloading all my ValueLists cause I know where this value came from. User has several different views of the table with different visible columns and he can switch between those views. I store views as XML. So now if user added some value to ValueList and then changed his view I should go to DB and reload all my ValueLists - it takes a lot of time and it is unnecessary cause all ValueLists are correct before loading from XML. So I was thinking may be I can store all ValueLists somehow before loading XML and then load it from memory. It should be faster than go to DB every time user changes his view. Please advice how to store/load ValueLists to memory if there is no other way to prevent ValueLists from XML loading.
Thank you.
Mila
When you load a DisplayLayout into the grid, the existing layout is replaced with the new one. Since the ValueLists are part of the layout, it would not make sense for the new layout to keep the existing ValueLists from the old layout. This would be very confusing and result in possibly memory leaks.
What I would probably recommend is that you create your ValueList externally to the grid. Instead of using the grid.DisplayLayout.ValueLists collection, you can just as easily declare a new ValueList as a form-level variable. Since the ValueList is not part of the DisplayLayout, then you don't have to worry about it being destroyed by the loading of the layout. The only thing you will have to do is set the ValueList property on the grid column(s) to re-attach the ValueList to the appropriate column after you load the layout.
I am telling you - I load grid and valuelists and then User can switch his view. Whats the problem with this easy operation? Why if user wants just to change his view he needs to wait till ValueLists will be loaded again? User can change values in ValueLists only from another place - not from the form there is grid shown. So I know exactly when I need to reload my ValueLists. The problem is - if user wants to just change his view (visible columns, columns widths, etc.) - then I load this view from an XML and it empties my ValueLists so I need to reload them from DB and user should wait 1 min till this happens. Whats the problem with it? If I am not storing ValueLists to XML then I don't need empty ValueLists to be loaded when I load from XML. Something is wrong with your SaveAsXML or LoadFromXML functions.
Well, then it sounds to me like you need to arrange the code so that the layout is loaded before you create and assign the ValueList to the grid.