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,
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
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.
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.
Sincerely,
Matt
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 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);
MattDeveloper Support Engineer