Hi,
I can save and load WinGridLayout , but Layout don't load. (use Infragistics .NET 2007 v7.3 fix 1043)
that I did not do so?
MemoryStream stream = new MemoryStream(); gridDocuments.DisplayLayout.SaveAsXml(stream, PropertyCategories.All); string strSettingsGrid = System.Text.Encoding.UTF8.GetString(stream.ToArray()); stream.Close();
//next save Layout in DB
//Load from DB and bindLayout
byte[ bt = System.Text.Encoding.UTF8.GetBytes(layout.xmlGridSettings); MemoryStream stream = new MemoryStream(bt, 0, bt.Length); gridDocuments.DisplayLayout.LoadFromXml(stream, PropertyCategories.All);
Thanks.
Thank you! Find reason of error, first base.OnInitializeLayout(e) and next LoadLayout
What is the error? There's no reason why the grouping should not be saved if everything else works.
Thanks for your answer. String work good. It's my mistakes, it been because I loadLayout and Bind data in different thread.
Now, i have some question more?
How save filters and Layout then i rebind data in Grid? How event call before datasource bind in grid and after data bind already? I want override this methods.
( I overrided OnInitializeLayout there save and load layout, it work with filters, but if i group by column and rebind data again, get error.)
public partial class MyGrid : UltraGrid {
private string strSettingsGrid; private bool isSave = false; private bool isFirst = true; public MyGrid() { InitializeComponent(); } private void SaveLayout() { MemoryStream stream = new MemoryStream(); this.DisplayLayout.SaveAsXml(stream, PropertyCategories.All); strSettingsGrid = System.Text.Encoding.UTF8.GetString(stream.ToArray()); stream.Close(); } private void LoadLayout() { byte[ bt = System.Text.Encoding.UTF8.GetBytes(strSettingsGrid); MemoryStream stream = new MemoryStream(bt, 0, bt.Length); try { this.DisplayLayout.LoadFromXml(stream, PropertyCategories.All); //this.DisplayLayout.LoadFromXml(stream1, PropertyCategories.All); } catch (Exception e) { // MessageBox.Show(e.Message); } }
/// <summary> /// Overriding initialization of layout - load layout from file and coloring every second row /// </summary> /// <param name="e"></param> protected override void OnInitializeLayout(InitializeLayoutEventArgs e) { if (this.DisplayLayout != null) { SaveLayout(); isSave = true; } //Loading layout of grid from settings file, it Layout bind only when application start
string fileName = User.GridSettingsPath + this.Parent.Name + this.Name + ".settings"; FileInfo fi = new FileInfo(fileName); if (fi.Exists) { try { e.Layout.Load(fi.FullName, PropertyCategories.Bands); } catch (Exception) { } } if (isSave && !isFirst) //then start project don't go inside, because isFerst = true
{ LoadLayout(); isSave = false; } isFirst = false;
//color alternate rows e.Layout.Bands[0].Override.RowAlternateAppearance.BackColor = User.CurrentUser.Appearance.AlternateRowColor; base.OnInitializeLayout(e); }
PS: Sorry for my English, hope you'll understand my questions.
Without more information, it's hard to guess. Are you changing the grid's data source in between the save and load? The layout you load has to match the data structure of the grid's data source. If it does not match exactly, it won't work.
Also, I'm not sure storing the bytes in a string like this will work. Why do you need a string? Why not just use the stream?