Hi,
I have Ultra Grid in windows application. I want to change column display order at runtime.
I'm wondering if there is a way to change the display order of column. Please help me ASAP
Yes, use the InitializeLayout event and set the column.Header.VisiblePosition on each column. Note that you must set the columns in order so as to prevent the positoin of one column from interfering with another.
So this is correct:
e.Layout.Bands[0].Columns["My First Column"].Header.VisiblePosition = 0;
e.Layout.Bands[0].Columns["My Second Column"].Header.VisiblePosition = 1;
e.Layout.Bands[0].Columns["My Third Column"].Header.VisiblePosition = 2;
This would be wrong:
e.Layout.Bands[0].Columns["My First Column"].Header.VisiblePosition = 2;
e.Layout.Bands[0].Columns["My Second Column"].Header.VisiblePosition = 0;
Hi Mike:
I have been trying to control the VisiblePosition of the columns in an Ultragrid (winforms) using an attribute on the DataSource's underlying type. The VisiblePosition doesn't seem to take - the columns result in an apparantly random order:
If it is still true in 2009.2 that we must set the column VisiblePosition in the order of the properties of the datasource type, due to how WinGrid uses reflection internally, then it seems to me that I need to go with the .Columns.FromKey[name].Move(#) strategy, and that my strategy will not work. Do you concur?
The seemingly random order is caused by the fact that your code is setting the Visible position in a random order. :)
You have to set the VisiblePosition of each column in order from 0 up. Otherwise, you run the risk that setting the VisiblePosition on a later column will alter the position of an earlier one.
In other words, set the column you want in position 0 first. Then the column you want in position 1, then 2, etc.
Hi Matt,
No, there's no way around this. What I would do is create some structure that holds a column (or the key) and the VisiblePosition that you ultimately want. Then you populate a list of those structures that has an item for each column. You can then sort the list by the visible positions and loop through them in order to set them on the real columns.
Mike,
Is there no way to overcome this limitation? We have some code that we use to dynamically set order on columns. Come to find, it is what you describe above that is most likely causing this code to have troubles. If there is no way around this, we'll have to rewrite some plumbing to allow the column positions to be assigned in order. Perhaps a newer version has created some solution for this? We are on version 9.1.20091.2012.
Thanks.
Matt