views:

788

answers:

1

I'm getting the following message when I try to remove the last item in a datagridview.

DataBinding cannot find a row in the list that is suitable for all bindings.

I have my binding setup as follows.

ExtendedBindingList<MyClass> bl = new ExtendedBindingList<MyClass>(GetDataFromDB());
BindingSource bs = new BindingSource();
bs.DataSource = bl;
dgv.DataSource = bs;

ExtendedBindingList is just something simple I threw together to implement sorting and filtering and some basic state persistence. dgv is the DataGridView. GetDataFromDB returns a List of MyClass.

The issue only arises when I try to remove the last item from the datagridview using:

bs.RemoveCurrent();

which works at all other times. My only hint for a solution is to remove all bindings and reapply them but this doesn't seem like an ideal solution.

EDIT The exception only gets thrown after the BindingList successfully removes the last item in question. It get's thrown in external code so I can't tell exactly what is throwing it.

So, here I am, asking SO for some help :).

Thanks in advance, Justin

A: 
nightcoder
I'm using a DataGridView not a Grid, but that is essentially what I'm using as well. It works every time except when I remove the last item.
Justin Drury
It is a DataGridView in my example. BindingSource is also used, but I delete from BindingListEx, not from BindingSource. Just try this code.I also think that your problem is somehow related to the last row which is for fast adding rows (AllowUserAddNewRows = true). I remember I had a problem with it and then I decided to turn it off (set AllowUserAddNewRows to false).
nightcoder
Hmm, I'll give that a try.
Justin Drury
Same exact error. It's happening in CurrencyManager.FindGoodRow(). which is marked as 'external code' in the call stack. I also have AllowUserAddNewRows set to false.
Justin Drury
Try calling bs.SuspendBinding() before deleting the row and bs.ResumeBinding() after deleting the row.
nightcoder
Do you do any manual binding?
nightcoder
Some, yes. The form is setup in a Master-Detail design. There are some comboboxs that get filled from another datasource and I need to do manual binding on those.
Justin Drury
SuspendBinding and ResumeBinding did nothing to help.
Justin Drury
Show me the code with the comboboxes bindings.
nightcoder
And also can you show the whole code with bindings and setting up the datasources.
nightcoder