Hi All,

I am using a custom collection (inherits collection base) and set it
as the datasource of the Datagrid. Everything works great except when
I delete the last row. WHEN I CLICK ON LAST ROW ON THE GRID IT GIVES
THE FOLLOWING ERROR :

"An UNHANDLED exception has occured in your application.If U click
Continue ,the application will ignore the error and attempt to
continue. If u click quit , the application will be shut down
immediately. Index was outside the bounds of the array!."

The title of the messagebox is 'error when committing the row to the
original datastore'. Im wondering how its going to commit the row to
the original datastore when its a custom collection of software
objects???

THE BUG happens EXCATLY when I delete the LAST ROW in the grid then
try to click anywhere in the grid!.


private void btnDeleteReference_Click(object sender, System.EventArgs
e)
{
if(referenceCollection.Count>0)
{
if(dgReferences.CurrentRowIndex >=0)
{
referenceCollection.RemoveReferenceAt(dgReferences.CurrentRowIndex,App.Connection
);
//dgReferences.CurrentRowIndex=0;
dgReferences.DataSource = null;
dgReferences.DataSource = referenceCollection;
dgReferences.Refresh();
//int i= referenceCollection.Count-1;
try
{
this.dgReferences.CurrentRowIndex = 0;
}
catch(Exception exxx){}
//dgReferences.CurrentRowIndex = referenceCollection.Count-1;
}
}
}

I've tried with several combinations of assigning a valid integer to
CurrentRowIndex ptoprty of the grid (Commented lines) to avoid the
error. Still it throws the exception telling Invalid index, index
should be non-negative or less than the bounds of the collection. I
tried to catch the exception while assiging an integer to the
currentRowIndx property, then too, exception is thrown by the
Application's Main form, parent of my Form.

What is this???
I found somewhere on the NET that this is a bug in MS Datagrid. But
the worst thing is that even the SelectedIndex property is failing to
work.

I AM REALLLY FRUSTRATED!!

Please help me out! :-(

Thanks in advance,
Sheetal