DataGridView error when using a filter on a BO


Author
Message
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
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. Unsure



So, any ideas why the datagridview is trying to index a row that isn't included in the new filter?



StrataFrame Team
S
StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)StrataFrame Developer (4.3K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
My guess would be that the event you're handling isn't expected by the .NET developers to repopulate the grid.  They probably have a test within the OnCellValueNeeded() to make sure that the cell belongs to the underlying data source.  However, once it's checked the first time, their method is probably expecting the data source's row to exist for the rest of the method (It's probably not very common to replace the data source during the CellValueNeeded event).  So, when the call stack works it's way back down to the .NET methods, they're not expecting the data source to have changed (it's probably not a condition they ever expected...).  Sorry, Greg, I don't know what to tell you...
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Thanks Ben, I'll look into that.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search