I have a DataGridView that I've bound to a BO via the BusinessBindgSource. I have a combo that allows the users to filter the contents displayed in the grid. It simply filters the BO, which filters the underlying datatable and viola, the grid is updated to display the new data. So far so good.
One of the columns displays some text based on the value of the underlying datatable and the state the form was opened in. I use the CellValueNeeded event to do the transformation. Still good.
This same column can be clicked to change the underlying value. When clicked, a sproc is fired that does some work, then the BO is refilled, re-filtered and the row reselected. Still good.
The problem occurs if I do click on a cell that does the above process, then select a new value in the combo that results in a set of records being displayed that is smaller then the current one AND the edited record's index is beyond those filtered records. I get a null exception, saying the index is out of range.
So these are the steps:
- Select a filter that has more items (more then the filter we select later)
- Edit one of the items (by clicking on the cell and running a sproc, updating the bo, reapplying the filter, reselecting the item)
- Select a filter that has less items (less than the current one)
I hope I've explained myself adequately.
So, any ideas why the datagridview is trying to index a row that isn't included in the new filter?