Hi,
I encountered a bug that in the event of AfterColPosChanged, the VisiblePosition returned from e.ColumnHeaders(0).VisiblePosition is wrong.
Example:
In the grid i have column1, column2 and column3 (Left to Right).
I removed Column2.
Drag Column1 into Column3 position.
Now in the AfterColPosChanged event, e.ColumnHeaders(0).VisiblePosition is 2, which is WRONG. It should be 1, because there is only 2 visible columns (zero based index)
Please help.
Hi Mike,
1st quote:
I cannot save the invisible columns. Reason: I have to toss them away and not save into database so that later time when user load the grid and the columns that were invisible should not be exists at all.
2nd Quote:
VisiblePosition NOT in order meaning when I walked thru the collection, it shows VisiblePosition as (2, 0, 1) from item 1 to item N (left to right columns on the grid). Which is not what I want, I need it to be 0, 1, 2.... etc. Also, again the visiblePosition still included the hiddencolumns but if the collection items are in order, i can easily fix it myself, problem is it's not in order.
And finally, I cannot use the built-in save/load layout, I have to save the column ID back to the database so that each Column must be a valid entry due to the foreign key constraints. Columns can be add/remove from database during the course, in that event, DB administrator has an idea of which column is no longer valid. If i save the layout to xml, that will screw up the backend DB job.
caspers said:What I was trying to do is I have to keep an index list of all visible columns in current order shown on the grid and write it to a database. The order has to be sequentially from 0 to N. I cannot use the visiblePosition because that's including the hidden column.
I don't see the problem.
If you want to save the column order, then why does it matter if you save the hidden columns VisiblePosition? I would think that you would want to do this. Otherwise, when you load the application and the user shows one of the columns that was hidden when they saved it, it will show up in the wrong place. So it makes sense to save the VisiblePosition of all of the columns.
Even if that's not what you want, why is it a problem to save the VisiblePositions of the columns with gaps?
caspers said:the ActiveColScrollRegion contains only VisibleHeaders but not sorted
I don't know what you mean by this. The VisibleHeaders collection is in the order of he visible columns.So you could simply walk over the collection and use the index as the position.
By the way... are you aware of the Save and Load methods on the grid.DisplayLayout? This will save the column order along with column size, sorting, filtering, etc. It saves and loads everything the user can change in the grid. So you don't have to write this code yourself.
What I was trying to do is I have to keep an index list of all visible columns in current order shown on the grid and write it to a database. The order has to be sequentially from 0 to N. I cannot use the visiblePosition because that's including the hidden column. the ActiveColScrollRegion contains only VisibleHeaders but not sorted and the value from VisiblePosition also a skipping index.
Is there an easy way to do this? In short, from my example earlier. Now the grid became Column3, Column1 (left to right). I need to find out Column3 (index 0), column1 (index 1). Column2 is hidden, I don't need that for now. If later I decided to bring column2 become visible again ===> COLUMN3, COLUMN2,COLUMN1 (index 0, 1, 2 respectively). The visiblePosition might probably messed up for now. I hope this will make more sense to you.
The VisiblePositions values you are getting here are correct. VisiblePosition is actually very flexible. You could, if you wanted to, set VisiblePosition to completely disparate values like 10, 20, 30, etc.
I'm not sure what you need the VisiblePosiiton values for, so it's hard to answer your question. But if you need to know what columns are actually visible an in what order, then I recommend that you use the grid.ActiveColScrollRegion.VisibleHeaders collection.
"Removed" means hide it (uncheck the box in columnchooser). So how can i work around this to get the correct visibleposition? Basically the column2 that is hidden now, column 1 and column 3 is visible on the grid. When I drag the column 1 to column 3 position, how can I tell what the new visible position is for the column1 on the grid ? I need to know the actual position that is shown on the grid, not including the hidden columns.