I have an untrawingrid bound to a custom collection.
There is a DisplayLayout that we've serialized to XML that we share with users.
We want to add an unbound column after the user loads the grid's displaylayout. The sequence looks like this:
Dim stream As New IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(LayoutString))myGrid.LoadFromXml(stream, PropertyCategories.All)myGrid.DisplayLayout.LoadFromXml(stream, PropertyCategories.All)
which works wonderfully. All the default columns and sizing/sorting/etc. is persisted.
However, when we try to add a column, it winds up overwriting an existing column (being displayed, but not in the underlying object itself, it seems):
myGrid.DisplayLayout.Bands(0).Columns.Add("isLocked")
As soon as we do this and the grid is refreshed, a column that used to be displayed is renamed "isLocked".
Looking at the displaylayout columns in code, everything seems fine, but the overwritten column will no longer be displayed.
Here's the displaylayout loaded:
here's what happens after calling myGrid.DisplayLayout.Bands(0).Columns.Add("isLocked"):
I feel like I'm doing everything right and maybe this is just a bug in the grid?
Okay. In that case, I've never seen a case where loading a layout changes the caption or key of the wrong column. We will probably need to see a sample so we can debug it and find out what's going on there. Are you sure it changing the existing column and not just showing the new column and hiding the original one? Are you sure the original column no longer exists? The grid creates columns that exist in the data source, and there is no way to remove a bound column. So if the column cannot be removed unless it's unbound. If it's bound, it can only be hidden, never removed. What's the RowLayoutStyle on the band? If you are using RowLayouts, it's also possible, though unusual, that two columns are occupying the same logical location and so you can only see one of them.
Thanks Mike. I changed the loading/saving methods to remove the specific encoding, and am still experiencing the same issue.
I use this persistence routine in several grids in my application, but this is the first time I've ever encountered this behavior.
I have the "before" displaylayout XML when the grid is displaying correctly and the "after" XML after I add an unbound column, and it's very different when running it through a diff tool.
Not sure if this is the issue, buy you should not be using an Encoding when saving or loading the stream data. That will likely damage the integrity of the data. There's another post about this here along with a better method of converting the stream to a string and vice versa.
Thanks Tihomir, yes, I'm sure with a pristine project I can get this to work.
The concern is with the real-world application where we have a persisted layout, correctly restoring/loading, and then adding a column overwrites an existing column. Surely this isn't the intended behavior.
Hello,
Thank you for posting on our forums.
Is it possible that the data source of the grid where you load the layout does not match the data source of the grid which was used to create the layout.
It is best to set the layout after the datasource have been already set. I have tested this on my end and the unbound column is being added at the end, as no other position is specified.
Attaching the sample for further reference.
In order to test it, change sorting, sizing of columns of the upper grid, save the layout(will have to adjust the path in the methods), then you can load the modified layout and add the unbound column.
Should you have further questions, please let me know.
Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics
GridLoadFromXML.zip