Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
9364
Notification when a new DataColumn is added to bound DataTable
posted

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!

 

Parents
  • 469350
    Offline posted

    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.

    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.

Reply Children