Those unfriendly MS Grid Controls

sidewinder58

New member
Joined
Apr 3, 2006
Messages
1
Programming Experience
5-10
Hi Folks

I have a slight prob with this DataGridView Control. Currently have a test app in which I have 2 bindingsource controls. To the first I have bound a simple object data class (Class A), which contains a SupplierID (Integer) property and a Cost (Decimal) property. To the other I have bound another simple data class (Class B) which contains an Id (Integer) property and a Name (String) property.

There are 2 columns in my control, the SupplierID which is a combobox column and the Cost which is a textbox formatted to Currency.

The control is bound to the first bindingsource and the combo column is bound to the second bindingsource. So the idea is to represent a pricing scheme for product at the suppliers who sell that product.

Then I created a simple collection class, to hold my items "Class A", which inherits from Collectionbase and also implements the IBindingList interface as illustrated in the MSDN example.

In the form load I set the datasource of the bindingsource controls, setting the reference data first (an array of "Class B") as the datasource of the bindingsource for my combobox. Next, set the data for the grid bindingsource (a collection containing 1 item).

Next, I run the app and I now have a datagridview control with one row and a new row showing only defaults.

Here is where the problems come in. If i click, at any speed, in the last row (new row) then the first, then the last row (new row) then the first, as soon as I click in the first row the second time it gives me ArgumentOutOfRange Exception saying 'rowIndex' is not within the range of acceptable values. - What is going on?

This same problem occurs when using the keyboard up/down keys, so i suspect that it may just be a problem that occurs when leaving the last row for a second time, but can't be sure. I do also know that it happens after RowValidating event and before RowValidated event.

The stack trace reveals that the problem lies in a Proc called GetCellDisplayRectangle, but I can't see any way around it.

Any help would be much appreciated!!
 
Back
Top