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
To get a column visible position check this: column.Header.VisiblePosition
http://help.infragistics.com/Help/NetAdvantage/NET/2008.3/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v8.3~Infragistics.Win.UltraWinGrid.ColumnHeader~VisiblePosition.html
thank you for your reply,
your code works great, but what if i want to sort the columns in columns array in the grid by VisiblePosition or somehow get a collection of columns sorted by 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.
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