The DataTable my Grid is bound has DataColumns added to it at run time.
I need this newly added DataColumn positioned correctly between two existing columns on the Grid.
What is the best way to make this happen?
1. Change the new DataColumn's ordinal position on the DataTable to be placed between the two column? Would doing so make the new UltraGridColumn show correctly between the corresponding two UltraGridColumns?
2. Not change the DataColumn ordinal. But instead position the new UltraGridColumn directly.
Questions
- Ideally it is #1 because then all my positioning logic can reside in the "data layer" logic. But I am not sure it will do the job for positioning corectly on Grid. Comment?
- If I have go with #2, how does the Grid get notified of a new UltraGridColumn being added? Any sample code (KB entry, etc) appreciated.
Thanks!
Mike Saltzman"] This is the way to go. The grid gets gets a notification from IList or IBindingList implementation of the data source. You could hook the same events. But since your code is adding the new column, you really don't need an event to tell you that this happen. You can simply add the column to the data source, then look for a column in the grid with the same key. You might have to call Refresh on the grid first to force the grid to paint, because the grid column might be created lazily.
This is the way to go. The grid gets gets a notification from IList or IBindingList implementation of the data source. You could hook the same events. But since your code is adding the new column, you really don't need an event to tell you that this happen. You can simply add the column to the data source, then look for a column in the grid with the same key.
You might have to call Refresh on the grid first to force the grid to paint, because the grid column might be created lazily.
Sounds good Mike!
The code adding the column is in the "data layer" of the application which does not know or care about the Grid. While the Grid itself is know the presentation layer. So I would like the presentation code to find out that a column got added and then position it. What event should my grid be handling for my requirement?
vrn said:1. Change the new DataColumn's ordinal position on the DataTable to be placed between the two column? Would doing so make the new UltraGridColumn show correctly between the corresponding two UltraGridColumns?
I don't beleive this will work. The grid will pick up the order of the columns from the DotNet BindingManager when it is bound. But after that, the columns can be moved in the grid independently of the data source. So moving them in the data source will not affect the grid.
vrn said:2. Not change the DataColumn ordinal. But instead position the new UltraGridColumn directly.