I have a grid where I have a number of databound columns and then I add a single column which is not databound. I move that column to position 0:
grid.DisplayLayout.Bands[0].Columns["MyColumn"].Header.VisiblePosition = 0;
This works great.
I save the layout XML and in subsequent runs, I reload the layout. As the user can re-order columns, my intent is for whatever the last column layout was to be used.
The grid is bound to a BindingSource with a DataSource set to an array of objects which implement an interface.
In future executions, things go roughly as follows:- I bind the grid to the BindingSource.- I set the DataSource of the BindingSource to an empty array of the interface (_bindingSource.DataSource = new IMyInterface[0];)- I load the layout from the XML file.
At this point, the Header.VisiblePosition for my column is properly set to 0.
- The user performs an action that loads data.- The BindingSource.DataSource is set to the data which is an array of the objects implementing IMyInterface.
Immediately prior to setting the BindingSource.DataSource, the VisiblePosition. After that line executes, my column order gets changed and my unbound column is now the last column.
I have 3 other grids that operate under the same algorithm roughly and the other 3 operate properly. I can't figure out what I'm doing differently here.
I thought I could subscribe to AfterColPosChanged to see what's triggering the change, but it doesn't seem to ever get called except when e.PosChanged = PosChanged.Sized. Why is that?Is there some way to know what's triggering the change in VisiblePosition?
Hi,
I'm afraid you lost me.
pdavis68 said:Immediately prior to setting the BindingSource.DataSource, the VisiblePosition.
There seem to be some words missing from this sentence. :)
Sorry, prior to setting the BindingSource.DataSource, the VisiblePosition of the Header is 0. Immediately after I set the BindingSource.DataSource, the VisiblePosition is 15 (which makes it the last column).When you run the app the first time, everything works just fine. I can bind new data over and over and my columns stay put. It's not until I re-run the app and the layout is loaded from XML that it doesn't work. I doubt the loading of the layout is to blame. I imagine I'm doing something in my code that's causing it to reset the columns, but I simply can't figure out what it is and was hoping there was some event that would let me know when the header is getting moved so I can see what's triggering it. I mean, binding the data is the root of it. But that's causing something to happen that's then resetting my column order.