We currently save grid layouts in a database using the .SaveAsXML method. We have added columns to the grid due to more info in the database. Is there a way to update existing layouts with the new columns?
I would think if you simply bind the grid, then load the layout, the new columns should still be there. At the very least, all that would happen is that the new columns would be hidden, in which case, you could just make them visible by setting the Hidden property to false.
Please accept my apologies, I completely misstated my question......We actually save the layouts in the XML format in a SQL Database. When the user loads the grid, we pull the layout from the table. Is there any way to modify the XML in the database to show the new columns in the layout.?
Hi,
I don't think so. I mean... I'm sure it's possible to modify the XML. But personally, I would not want to attempt it. The XML for a serialized column is very complex and trying to manually modify it is no small undertaking.
It would be a lot easier to create a dummy grid with a dummy data source (like UltraDataSource) that just has the structure you want, and then load the layout into the grid, modify it, and re-save it.
We have a similar situation in that we want to be able to add columns to the grid.
Currently the code is set up in the initialize grid event to set visibility and such, then call the LoadGridlayout. In the InitializeGrid event, we loop through the columns and using a select case we handle the columns. We have a Case Else that handles those columns that we do not want visible or have not coded for yet. If a column falls into this Case Else (which all new columns not coded yet should), then they should be hidden. However, when I add a new column to the dataset, it is visible instead of being hidden. If I skip over the LoadLayout call, it is hidden as expected.
Why then, does the layout overwrite a column's properties that did not exist in its saved layout?
To give you the basics of what we are doing:
UltraGrid1.DataSource = DataSet
followed by (a few lines later) the load layout
UltraGrid1.DisplayLayout.LoadFromXml(layoutStream, Infragistics.Win.UltraWinGrid.PropertyCategories.All)
The Datsource line fires off the Initialize event (_InitializeLayout)
Here we loop thru the columns and if we are not expecting it or do not want to do anything special with it, we want to hide it. So in a Case Else we set the Column's Hidden property = True
After this occurs, the load layout line fires, and the column still shows.
Loading the layout will completely blow away any layout settings you have applied in code. It sounds to me like you need to load the layout from the file BEFORE you run your code, not after.
What we want is for all the "old stuff" in the layout, use the users preference. But for any new columns, add it to the grid and use our settings (which would then get added to the user's layout when the user exit the screen).
So, by what you are saying, do you mean we would have to say: If this is the first time in here after we made a change to the layout, then set the column properties again after we load layout so that they are in the correct position, size, visibility for the defaults?
Thanks Mike for the info. That helped.
For those that could use a little further information:
1) Create a variable of type Infragistics.Win.UltraWinGrid.UltraGridDisplayLayout and use its LoadFromXML method (same as the grid).
2) Do what you need to do to the layout
3) Then to add the layout to the grid, the grid's layout has a Load method that takes the layout and other parameter.
The layout can't know that you want to keep some settings and remove others. When you load a layout, it loads everything. There's no way to merge a layout with the existing setting in the grid.
Perhaps what you should do is load the layout into a Layout variable instead of loading it into the grid. Then you can examine the layout columns and the actual grid columns and decide what you want to do from there. You could then modify the loaded layout to use some of the existing grid settings before you load it into the grid.