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?
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 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.
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.