I am saving the columns of a XAMGrid using the persistance manager. If I add a new column to the grid and then load the settings back in, the new columns are no longer there and cannot be shown.
HI Edwin,
You could wire up the PersistenceSettings' Objects' Loaded Event. In that event you could add the new columns.
Here is a code snippet:
ObservableCollection<Person> people = new ObservableCollection<Person>();
PersistenceGroup _SettingsGroup;
PersistenceSettings settings;
string fileName = "TEST";
public MainPage()
{
InitializeComponent();
_SettingsGroup = (PersistenceGroup) LayoutRoot.Resources["SETTINGS"] as PersistenceGroup;
settings = (PersistenceSettings)LayoutRoot.Resources["ColumnSettings"] as PersistenceSettings;
settings.Events.PersistenceSaved += new EventHandler<PersistenceSavedEventArgs>(Events_PersistenceSaved);
settings.Events.PersistenceLoaded += new EventHandler<PersistenceLoadedEventArgs>(Events_PersistenceLoaded);
}
void Events_PersistenceLoaded(object sender, PersistenceLoadedEventArgs e)
//throw new NotImplementedException();
foreach (Column c in xgrid1.Columns)
int i = int.Parse(c.Tag.ToString());
xgrid1.Columns.Remove(c);
xgrid1.Columns.Insert(i, c);
Sincerely,
MattDeveloper Support Engineer
I would like to have a more general solution. I have an application with several windows and some window have multiple grids. Keeping code the handle all of the cases for new columns will be messy over time.
HI,
It doesn't have to be messy. You could create a helper class that has two methods. These methods will do the following:
1) Method-1 takes the XamGrid as input, and returns its OrigColumnCollection.
2) Method-2 takes the XamGrid and OrigColumnCollection as input and traverses the OrigColumnCollection and compares it with XamGrid's ColumnCollection and insert any missing columns.
Before reloading any persisted settings, call method 1.
After loading any persisted settings. call method 2.
Matt
Developer Support Engineer
Hello,
I have been looking into Matt's sample and I modified it so now the sorting is applied after loading the settings. Basically when the column is removed and then added the sorting is reset, this is why I save the sort direction in a temp variable and set it after the remove/add operations.
@Matt:
Thank you for taking the time to reply to John's posting.
Unfortunately, if you try to use the approach outlined in the sample code AND save the column's sort direction (e.g. ascending/descending)... the sort settings are lost when you re-order the columns.
Are you able to observe the same results? Do you have any recommendations on how to mitigate this problem?
STEPS TO REPRODUCE
COLUMN REORDERING CODE (from: MainPage.Xaml.cs)
{ int i = int.Parse(c.Tag.ToString()); xgrid1.Columns.Remove(c); xgrid1.Columns.Insert(i, c); }
Please let me know if you need further assistance regarding this case.
Sincerely, Matt
You do not have to save the whole column collection.
Here sample that saves the column order and width.
I only want to save certain things about columns (width, ordering, sorting, grouping, filtering). right now my persistance settings look like this
PersistenceSettings set = new PersistenceSettings(); set.LoadPersistenceOptions = Infragistics.Persistence.Primitives.PersistenceOption.OnlySpecified; set.SavePersistenceOptions = Infragistics.Persistence.Primitives.PersistenceOption.OnlySpecified; PropertyNamePersistenceInfo nInfo = new PropertyNamePersistenceInfo(); nInfo.PropertyName = "Columns"; nInfo.Options = Infragistics.Persistence.Primitives.PropertyNamePersistenceOptions.PropertyName; set.PropertySettings.Add(nInfo); nInfo = new PropertyNamePersistenceInfo(); nInfo.PropertyName = "FilteringSettings"; nInfo.Options = Infragistics.Persistence.Primitives.PropertyNamePersistenceOptions.PropertyName; set.PropertySettings.Add(nInfo); nInfo = new PropertyNamePersistenceInfo(); nInfo.PropertyName = "SortedColumns"; nInfo.Options = Infragistics.Persistence.Primitives.PropertyNamePersistenceOptions.Contains; set.PropertySettings.Add(nInfo); nInfo = new PropertyNamePersistenceInfo(); nInfo.PropertyName = "GroupByColumns"; nInfo.Options = Infragistics.Persistence.Primitives.PropertyNamePersistenceOptions.Contains; set.PropertySettings.Add(nInfo); nInfo = new PropertyNamePersistenceInfo(); nInfo.PropertyName = "SummaryRowSettings"; nInfo.Options = Infragistics.Persistence.Primitives.PropertyNamePersistenceOptions.PropertyName; set.PropertySettings.Add(nInfo);
But this saves a lot more information than I need. Is there a simple way to do what I want?