I'm using a pretty simple WinGrid that is bound to a BindingList of custom objects. When adding new items to the list, I'm not using the WinGrid to do so, because the objects need a bit of initialization (ie. there is no default constructor). Instead, I am creating the object, initializing it and then adding it to the BindingList. The WinGrid is picking up the new object and adding a new row for it, however I want the grid to make that new row active. I thought that the AfterRowInsert event would be raised in this case and I could just set the active row here, but that event simply isn't being raised. Am I missing something here? Is there some other event I can get when this happens?
IGDrewS said: If you know the index of the item in the binding list then you get the row from the grid as follows. grid.Rows.GetRowWithListIndex(index)
If you know the index of the item in the binding list then you get the row from the grid as follows.
grid.Rows.GetRowWithListIndex(index)
That did it alright - hooking into the BindingList's ListChanged event, I can get the index then use this method to get the row and set the active row. Thanks!
IGDrewS said: If you are initializing and adding the item manually can you also set the active row manually? You could also handle the binding list events. Init Item Add Item to List set grid.ActiveRow
If you are initializing and adding the item manually can you also set the active row manually? You could also handle the binding list events.
Init Item
Add Item to List
set grid.ActiveRow
This would only work if I knew what row it was creating - that's what I thought that AfterRowInsert would do, as one of the event arguments is the row that was inserted.
I'll have to look into the CurrencyManager and see what I can do with that.
Also, the grid will synchronize the active row with the position of the CurrencyManager by default. So you could just set the CurrencyManager position or the Current object to the newly-added row and that will update the grid.