I want to save an load layouts of an ultragrid. This is no problem wih SaveAsXm. But I want to ask the User if he wants to save a changed layout.
Is there any way to compare 2 layouts (current and a perviously saved).
.Equals(object) seems to have no effect.
{
UltraGridLayout LoadedLayout = ultraGrid1.DisplayLayout.Clone();bool isEqual = LoadedLayout.Equals(ultraGrid1.DisplayLayout); // is false
}
I don't think there is any simple way to do this. Layouts are pretty complex with lots of properties, and the Equals method will just do a reference comparison.
I suppose one way to do this would be to write each layout into a stream and them loop through the stream and compare each Byte. I'm not sure how efficient this would be, though.
I was afraid you could say this.
At addition. I compare the pure layout String, cause I want to save the layout to my database.
toString:
MemoryStream firstStream = new MemoryStream(); this.Grid.DisplayLayout.SaveAsXml(firstStream); //this.Grid is my UltraGrid
Encoding encoding = System.Text.Encoding.Default; string result = encoding.GetString(firstStream.ToArray()); firstStream.Close();
LoadFromString:
MemoryStream test = null; try { // this.LoadedLayout is the loaded Layout String
test = new MemoryStream(System.Text.UTF8Encoding.Default.GetBytes(this.LoadedLayout));
this.Grid.DisplayLayout.LoadFromXml(test); //this.Grid is my UltraGrid } catch (System.Exception e) {
//Logging } finally { if(null != test)
test.Close(); }