Datagrid

  • Thread starter Thread starter avi
  • Start date Start date
A

avi

I have a datagrid which is binded to an ArrayList.
The user can add or delete entries to / from the
ArralyList object, afterwards the change needs to be
reflected in the datagrid.
I used the datagrid method SetDataBinding() after each add
or delete requests as follows:
first using null:
dataGrid1.SetDataBinding(null,"");
second:
dataGrid1.SetDataBinding(myArrayList,"");

The add process works but the delete sometimes doesn't. If
the last row had been deleted I recive
a "System.IndexOutOfRangeException" exception.
Any suggestions???
 
If possible, before doing your delete, try setting the
dataGrid1.CurrentRowIndex to a value that will be valid after your delete
(maybe decrement by 1).

==================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
I just recently had the same exception (IndexOutOfRangeException) thrown
when binding a class that I inherited from CollectionBase to a listbox.
Instead of SetDataBinding to null try using:

this.BindingContext[your data source obj].SuspendBinding()
// delete code here
this.BindingContext[your data source obj.].ResumeBinding()

This worked for me; however, I wish I knew why the exception was being
raised.

William.
 
Back
Top