Hi!
I'm using the following functions to save and load filters:
private const PropertyCategories CategoriesToSave = PropertyCategories.ColumnFilters; public override void AdditionalSave(Control x, string path) { var g = x as UltraGrid; var layout = g.DisplayLayout; var newpath = string.Format("{0}{1}_gridProps.lyt", path, g.Name); layout.Save(newpath, CategoriesToSave); } public override bool AdditionalLoad(Control x, string path) { bool ret = true; var g = x as UltraGrid; var layout = g.DisplayLayout; var newpath = string.Format("{0}{1}_gridProps.lyt", path, g.Name); if (File.Exists(newpath)) { layout.Load(newpath, CategoriesToSave); } return ret; }
The Load of the grid resets the other properties of the grid (for example ExcludeFromColumnChooser). This is not desirable in my situation. I was fully expecting the loading of filters to be merely additive with no other impact on the grid. Can you explain how I can achieve this?
Thanks!
Craig
Egad, sorry about the formatting of my comment after the code. Here's that text again hopefully not formatted as code:
Hi,
You can't save the filters without also saving the columns. So any properties of the columns will also be saved and loaded along with this code. I'm not sure exactly what you mean when you say "reset". If the ExcludeFromColumnChooser property that is being loaded is something different from when it was saved, then something is wrong.But I've never seen anything like that happens.
If you want more fine control over what is loaded, then one thing you could do is... don't load the layout directly into the grid's DisplayLayout. You can create an UltraGridLayout variable in code and load your layout into that variable. Then you would have to loop through the ColumnFilters and copy them (re-create them) in the grid's DisplayLayout.
My previous post was attempting to stop you from doing any research into the bug. My apologies if I wasn't clear. I think I understand why situation occurred.
My scenario is slightly different from your above example. In my situation I'm not saving the ExcludeFromColumnChooser to the XML or binary file. Instead I'm saving and loading just the filtering information. The reason, in my code, that the ExcludeFromColumnChooser property is reset is because Load creates a new Layout object rather than merely adding (for some reason I thought "|=") the loaded properties to the existing layout. The new layout object uses default values for those values not loaded from the file.
Hello Craig,
Thank you for your feedback!
I am checking to see if you need any further assistance on this.
Hi Boris,
No, not for now. Unfortunately the effort to complete this would take too much time for where we are in our development cycle. It has been deferred till the next release. This information has proven quite useful though. Thanks again to you and Mike!
Ha! I wrote my response believing that this was a different thread. My apologies.
The information here as proven quite useful and I'm already using it. Thanks again! Please consider this topic closed.
For those interested, this seems to be working although I'm not sure if it is working properly with multiple bands in the same grid. Anyway, it should help anyone get started with this issue:
private const PropertyCategories CategoriesToSave = PropertyCategories.ColumnFilters;
private static string LayoutFilePath(string path, UltraGrid g, UltraGridBand b) { return string.Format("{0}{1}_{2}_gridProps.lyt", path, g.Name, b.Index); }
public override bool AdditionalLoad(Control x, string path) { bool ret = true; var g = x as UltraGrid; var layout = g.DisplayLayout.Clone(); foreach (var b in g.DisplayLayout.Bands) { if (b.Override.RowFilterMode.In(RowFilterMode.AllRowsInBand, RowFilterMode.Default) && b.Override.AllowRowFiltering.In(DefaultableBoolean.True, DefaultableBoolean.Default)) { var newpath = LayoutFilePath(path, g, b); if (File.Exists(newpath)) { layout.Load(newpath, CategoriesToSave); g.DisplayLayout.Bands[b.Index].ColumnFilters.ClearAllFilters(); g.DisplayLayout.Bands[b.Index].ColumnFilters.CopyFrom(layout.Bands[b.Index].ColumnFilters); } } } return ret; }