i have a grid,i want to save the name of the columns in a file after i change the order of the columns (by drag and drop), i have tried to loop on the columns but every time in return the columns with its initial stat (before i change the order of the columns)
how can i do that?
thanks
I'm not sure what you mean by "multiple column rows." If you just want to save the order of your columns in the grid, then the simplest thing to do is use:
grid.DisplayLayout.Save or SaveAsXml. That will save the entire layout of your grid.
The link above is to an old version, which is why it's no longer working. But it's really not neccessary. It's just a link to the topic for the VisiblePosition property on the column header:
grid.DisplayLayout.Bands[0].Columns[0].Header.VisiblePosition
Here's an updated link:
https://es.infragistics.com/help/winforms/infragistics.win.ultrawingrid~infragistics.win.ultrawingrid.columnheader~visibleposition
But as I said, it's better to just save the layout, rather than trying to manually implement saving and loading the column positions yourself.
Hi,
The above link is not working ,actually i also want to save the multiple column bound, I'm able to save single column soft order ,but not able to do same with multiple column rows.
VisiblePosition is a bit tricky. It's possible for two columns to have the same VisiblePosition, in which case, the grid will fall back to the column's Index. Sorting them is fairly simple - there's a Sort method on List<T>, now, but you could have to pass in a sort comparer to make sure the sorting is done in exactly the same way as the grid's internal sorting works, and there's no way for you to get the same comparer the grid uses.
I think an easier solution would be to loop through the columns in order and explicitly assign a VisiblePosition for each one based on it's actual position.That way you ensure there are no duplicates.
Here's some sample code that will get you a list of the visible columns in the grid, in order:
UltraGridBand band = this.ultraGrid1.DisplayLayout.Bands[0]; List<UltraGridColumn> visibleColumns = new List<UltraGridColumn>(band.Columns.Count); int visiblePosition = 0; UltraGridColumn column = band.GetFirstVisibleCol(this.ultraGrid1.ActiveColScrollRegion, true); while (column != null) { visibleColumns.Add(column); column = column.GetRelatedVisibleColumn(VisibleRelation.Next); }
i did but it save a lot of information which i don't need.
i just need the name of the columns in order of their VisiblePosition
Why don't you simply use the save and load method on the grid's DisplayLayout? That would be a lot easier, as all of the work is done for you.