I have a UltraGrid on my form. When it is first popluted, code sets the values of the DisplayLayout. I then save the displaylayout in a file as the original. I will then check to see if there is a second file with the users saved displaylayout and load that. This will set the display layout to the same settings the last time the user closed this form. A user can then resize columns, reorder and sort etc.
If the user right clicks on the grid a context menu will reset the display layout using the original saved displaylayout and also save this layout as the user defined layout. When the user closes the form the orignal layout file is deleted and the user defined layout file is saved.
Here's my problem. We are about to release a new version of our software and there are some new columns added to collection that is bound to the grid. The first time the user opens this form in the new release it will again save the original display layout (New fields are hidden) and then load the existing displaylayout file. However the new columns that were added in the collection are also shown because they are not part of the display layout and they are visible by default. In our case we don't want these fields to be visible. The user will have to right click and reset the layout in order hide these fields as we intended. (These new fields have sensitive information)
I tried a few different approches. I looped through the columns and set hidden = true. Then set the display layout. No luck. I then hid all the columns again and tried the displaylayout.CopyFrom method. No luck.
Here are some questions.
1. What would be the best approach to handle this.2. If we had removed a column from the collection would this blow up.3. I saved and loaded the DiplayLayout without specifiying PropertyCategories.(What is the default) What should I have done there.
Thanks in advance.
Dan
Aye my example essentially does that, I just don't use the "CopyFrom". I simply hide the columns on the main grid that are not in the layout variable using the exists() command.
Hi,
Yes, I think you are probably right. Those columns are no longer "new" and do they don't get hidden.
If you need such fine control over what happens when you load the layout, then perhaps what you could do is load the layout into a variable and modify it before loading it into the grid.
You can declare a variable of type UltraGridLayout and load the layout into it. Then you can examine the layout, bands, and columns and set properties on them, hiding whichever columns you choose. Then you use the grid.DisplayLayout.CopyFrom method to copy the layout variable into your grid.
I am having the same problem, however the fix has not worked for me. It works when I select the first layout but soon as I select another layout (As there is an option to select from several layouts saved) the new columns appear, is it because these columns are no longer "new columns" so now they already exist?
If I try the other option of hiding the columns not in the layout then this does get around the problem. I got it working with the following code;
Dim layout As UltraGridLayout = Nothing Dim xmlLayout as string 'Load in any grid formating or totals and update the layout name in use (byref) xmlLayout = _SQLMain.LoadProgrammeLayout(_CurrentProgrammeLayout) If xmlLayout <> "" Then ' Create a MemoryStream Dim MStream As MemoryStream = New MemoryStream
Dim WStream As New StreamWriter(MStream)
'Write the xml configuration to the stream WStream.Write(xmlLayout) WStream.Flush()
'Move back to the beginning of the stream MStream.Position = 0
ugrProgrammeView.DisplayLayout.LoadFromXml(MStream, PropertyCategories.AppearanceCollection Or PropertyCategories.Bands Or PropertyCategories.ColScrollRegions Or PropertyCategories.General Or PropertyCategories.Groups Or PropertyCategories.RowScrollRegions Or PropertyCategories.SortedColumns Or PropertyCategories.Summaries Or PropertyCategories.UnboundColumns Or PropertyCategories.ValueLists) 'Load the stream for the second layout file to compare against later. WStream.Write(xmlLayout) WStream.Flush() MStream.Position = 0 layout = New UltraGridLayout layout.LoadFromXml(MStream, PropertyCategories.AppearanceCollection Or PropertyCategories.Bands Or PropertyCategories.ColScrollRegions Or PropertyCategories.General Or PropertyCategories.Groups Or PropertyCategories.RowScrollRegions Or PropertyCategories.SortedColumns Or PropertyCategories.Summaries Or PropertyCategories.UnboundColumns Or PropertyCategories.ValueLists)
_ProgrammeLayoutLoaded = True End If
'Load the datasource ugrProgrammeView.DataSource = _SQLMain.LoadProgrammeView(gCurrentGroupScenarioId) 'Loop through and compare layouts to hide new columns, as the NewColumnLoadStyle property does not do this. If IsNothing(layout) = False Then For Each col In ugrProgrammeView.DisplayLayout.Bands(0).Columns If layout.Bands(0).Columns.Exists(col.Key) = False Then col.Hidden = True End If Next End If
Hi Mike,
just to let you know, the approach using NewColumnLoadStyle" worked like a charm.Thanks again for your help!
Thanks for the information Mike.The NewColumnLoadStyle property sounds promising, I am going to implement this on Monday and post if it worked.In the meantime thanks again for your help,
best regards
Andy