I save layouts to a stream using:
grid.DisplayLayout.Save(stream, flags);
which I save to the database as a byte array.Then, when I want to load the layout, I use: grid.DisplayLayout.Load(stream);So far so good.The problem I am having is that I need to know what columns a user has displayed, but without loading the layout into a grid (basically business logic related to visible grid columns is in an area of the application that does not have a grid displayed, not does it make sense to display one).
When I try to decode the layout byte stream: Encoding.Default.GetString(layoutByteArray);The data is not easy to decipher, below is a snippet:I notice that it contains null terminators, control codes, and other odd characters.Is there a way to decode this?
0546A52EF7F61F69CA29B4B6634A1B420FD68C22 said:For the binary content, it would be best to deserialize it back to an UltraGridLayout to read the column information.
Just to clarify... what this means is that you can define a variable in code as a new UltraGridLayout and load the layout into that variable (instead of into the grid;'s DisplayLayout). You can then examine the object model, the bands collection, the columns of each band, etc. completely external to the grid.
UltraGridLayout layout = new UltraGridLayout(); layout.Load(filename); foreach (var band in layout.Bands) { foreach (var column in band.Columns) { Debug.WriteLine(column.Hidden); } }
The best approach if you need to be able to parse the layout is to use the SaveAsXml and LoadFromXml methods to load and save the layout as you can actually parse the XML.
For the binary content, it would be best to deserialize it back to an UltraGridLayout to read the column information. For persistence of binary layouts, we use the BinaryFormatter with AssemblyFormat set to Simple to save and load the layout internally. If you want to see more details on how this is done it would be best to download our source code review that to see if there is logic that you could use.
Assuming that the reason for not wanting to load a grid in your business logic is because the grid assembly isn't referenced, then deserializing the binary object may not be a viable option. The stackoverflow question: Convert from binary to XML serialization without needing the type doesn't appear to have a solution.
Another alternative is to also read the column information on your own from the grid when serializing the layout and also serialize the column information on your own in a format that you can read in your business logic.
Let me know if you have any questions