S
Sean Carpenter
I have a DataGrid in my application that is bound to a custom collection of
business objects. The collection inherits from CollectionBase so is
bindable. My problem occurs when I remove an item from the collection.
After the removal, any time I click on the grid, I get an un-catchable
ArgumentOutofRange exception. I tried a few workarounds:
1. Before removing an item from the collection, I set the DataSource of the
grid = Nothing. Then I removed the item, set the DataSource back to the
collection, and called Refresh. This caused the grid to re-display with the
removed item gone, but as soon as I clicked on the grid, I got the
exception.
2. I added an IBindingList implementation to my collection and set
SupportsChangeNotification to True. I raised the ListChanged event in the
Add and RemoveAt methods of the collection. This caused the grid to update
correctly without resetting the DataSource, but I still got the exception
when clicking on the grid.
By the way, I get the exception whether or not there are any event handlers
attached to grid. Any advice would be appreciated.
Thanks,
Sean Carpenter
business objects. The collection inherits from CollectionBase so is
bindable. My problem occurs when I remove an item from the collection.
After the removal, any time I click on the grid, I get an un-catchable
ArgumentOutofRange exception. I tried a few workarounds:
1. Before removing an item from the collection, I set the DataSource of the
grid = Nothing. Then I removed the item, set the DataSource back to the
collection, and called Refresh. This caused the grid to re-display with the
removed item gone, but as soon as I clicked on the grid, I got the
exception.
2. I added an IBindingList implementation to my collection and set
SupportsChangeNotification to True. I raised the ListChanged event in the
Add and RemoveAt methods of the collection. This caused the grid to update
correctly without resetting the DataSource, but I still got the exception
when clicking on the grid.
By the way, I get the exception whether or not there are any event handlers
attached to grid. Any advice would be appreciated.
Thanks,
Sean Carpenter