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
This works, but loading the columns from the old layout seems to remove custom cell styles that I had for some columns.
The column object has CellStyle so you could set that when you add a new column to the XamGrid.
Here a link to the Column API:
http://help.infragistics.com/NetAdvantage/Silverlight/2013.1/CLR4.0/?page=InfragisticsSL5.Controls.Grids.XamGrid.v13.1~Infragistics.Controls.Grids.Column_members.html
Sincerely, Matt
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?
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.
You do not have to save the whole column collection.
Here sample that saves the column order and width.