I'm working on an application where we need to "remember" the order of the columns in an UltraWinGrid. As the application is closing, I cycle through all of the columns in the grid and grab the visible position and then save all of the values to the database. When the application is re-started, I get all of the visible positions from the database and loop through the columns of the grid to set the visible position of each column.
The problem that I'm having is that the VisiblePosition property does not appear to be updating. I've debugged the closing event of the application and checked the VisiblePosition of the columns, but they are the same as when the application started, ignoring any changes I had made. Is this the best approach to follow? If so, why would the property not be getting updated? I've tried referencing the ColumnsCollection of the grid through Grid.DisplayLayout.Bands[0].Columns and Grid.Rows.Band.Columns and they function the same.
Thanks, Ryan.
Hi Srivasta,
If you are using RowLayouts, then the VisiblePosition property is ignored in favor of the OriginX on the RowLayoutColumnInfo. So you would have to change the layout using the RowLayoutColumnInfo. This is much more complex, since you will have to modify the other elements in the layout so they do not overlap.
Note that if you do not set the OriginX, the grid will fall back to using VisiblePosition in a simple layout. So if you are not stacking columns vertically, then you might be able to achieve what you want by resetting all of the OriginX properties on all of your column's RowLayoutColumnInfo and then setting the VisiblePosition.
Hi Mike
I am using RowLayoutColumnInfo for setting the entire layout, i am using it in usercontrol so i need to change the visible position based on some cateogory, can you please tell me how can i change the visible position of the column if i use RowLayoutColumnInfo.
Thanks
Srivasta
Hi Ryan,
Why not use the grid.DisplayLayout.Save/Load methods? That would save you a lot of code.
If you can't use those for some reason, then my guess is that you are probably setting the VisiblePosition on the columns either in the wrong event or in the wrong order.
I would recommend using the InitializeLayout event. When you set the VisiblePosition, make sure you set them in order from 0 up. Otherwise, you run the risk of setting the VisiblePosition on one column and having that affect the position of other columns.
So for example:
e.Layout.Bands[0].Columns["A"].Header.VisiblePosition = 0;
e.Layout.Bands[0].Columns["B"].Header.VisiblePosition = 1;
e.Layout.Bands[0].Columns["C"].Header.VisiblePosition = 2;
e.Layout.Bands[0].Columns["D"].Header.VisiblePosition = 3;
Another possibly issue here is if you are usnig RowLayouts. If you are, then the VisiblePosition property is not used because the column positions are determined by the RowLayoutInfo on the column.