Hi All,
i have a winform ui that starts up and loads layout from xml. The user can sort, resize, hide columns. when they do that i want to set a flag so that when the app closes it will say , "layout has changed do you want to keep the changes?" i'm not able to find where to set the flag.
can you help?
Hi Al,
The only way for you to establish a baseline using this approach is to wait until after all of your code changes to the grid are done and then save the layout at that point. If your application is continuously making changes to the layout and you don't want those changes to 'count' as a change, then using this stream-comparison approach might not be the right way to go. Comparing the streams is a very brute-force, all-or-nothing way to compare the layouts.
If you know what kinds of changes your application makes, and therefore which ones you want to ignore in the layout, then you could actually load the layout from the stream into an UltraGridLayout variable. This allows you to examine the properties of the layout in code without actually loading it into your grid control. So in theory, you might be able to load the original layout into memory and then compare certain properties to the grid's actual DisplayLayout and check for certain specific changes. But this is not trivial and you would have to check every possible property that the user might have changed.
The alternative approach would be for you to handle any grid event which fires when the user changes something. There is no single event for this, but there are individual events for any changes the user might make, such as AfterSortChanged, AfterRowFilterChanged, AfterColPosChanged, etc. So you could handle all such events and mark a flag when they fire.
Frankly, I think most people find it easier to just always save the layout whether the user has changed anything or not.
hi Michael, that's a good example thanks. i've still got to find what property is being set that my layout is changing. i don't have a baseline at the moment.
thanks
Hello Al,
Here is a way you could compare two streams:
private static bool CompareMemoryStreams(MemoryStream ms1, MemoryStream ms2)
{ if (ms1.Length != ms2.Length) return false; ms1.Position = 0; ms2.Position = 0; var msArray1 = ms1.ToArray(); var msArray2 = ms2.ToArray(); return msArray1.SequenceEqual(msArray2); }
http://stackoverflow.com/questions/2978727/most-efficient-way-to-compare-a-memorystream-to-a-file-c-sharp-net
Let me know if you have any additional questions
Thanks for responding Michael, that does make sense but i think this code is making additional layout changes at runtime. it loads from a xml file but then applies additional changes. im not capturing the exact last layout. so my beforestream.length != afterstream.lenth regardsless of any UI changes made by user. i'll work on finding the property being set.
thanks again
To properly keep track of the layout currently in use before, while, an after the end user is in session you can perform the following:
ie. The following article will help you perform the commands needed below:http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=1036
1. Save the grid's current layout to a memory stream immediately upon first use. (form's load event) 2. Overwrite stream 1 (step 1) if you plan on loading any preexisting layout or expect your user's to load their own (eg. Open Dialog ==> choose existing layout)
-- changes are then made by the end user
3. Handle the close event of the form and create a second new stream (do not overwrite stream 1).4. Do a comparison on the closing event between the two streams based on the length in bytes. If any changes were made you could then proceed with your message and a popup, if necessary, MessageBox with buttons.YesNoCancel.
Let me know if you have any questions regarding this matter.