hitechboy78737
Programmer
When deleting a single row from a CF datagrid, I get the following error:
"IndexOutOfRangeException Index 2 is not non-negative and below the total rows count"
When I delete ALL the rows, I do not get this error.
I understand WHAT the error is saying, and I think I understand WHY it is thrown... but I'm at a loss how to avoid it.
Following is the code that throws the error:
Thanks once again for your help!
Kevin Howell
Briefcase of Talent- Austin, Texas
"IndexOutOfRangeException Index 2 is not non-negative and below the total rows count"
When I delete ALL the rows, I do not get this error.
I understand WHAT the error is saying, and I think I understand WHY it is thrown... but I'm at a loss how to avoid it.
Following is the code that throws the error:
Code:
Private Sub mnuDeleteSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDeleteSelected.Click
Try
'get selected row index
Dim selIndex As Integer = dg1.CurrentRowIndex
If selIndex > -1 Then
'remove the row from the row collection
objGlobal.workingDataTable.Rows.RemoveAt(dg1.CurrentCell.RowNumber)
'update xml
objData.saveDataTableToXML()
End If
Catch ex As Exception
objGlobal.showError(ex)
End Try
End Sub
Thanks once again for your help!
Kevin Howell
Briefcase of Talent- Austin, Texas