Hi there. I have a datagridview control that i populate with records from my database. i'm now working on a feature where the user can select multiple records to remove from the datagridview. I do this by setting a certain value to NULL. It works only if the user selects no more than 2 records. The minute more than 2 are selected, i get the following error:
Here's the code:
Any suggestions? ALso, i tried to change the hard coded value of 16 to the actual name of the field but it doesn't recognize it. What am I missing?
Thanks.
"Index was out of range. Must be non-negative and less than the size of the collection"
Here's the code:
VB.NET:
Private Sub btnDeleteHHFromTerritory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteHHFromTerritory.Click
Dim i As Integer = 0
Dim selectedrowcount As Integer = HouseHolderDataGridView.SelectedRows.Count
If selectedrowcount > 0 Then
For i = 0 To selectedrowcount - 1
HouseHolderDataGridView.SelectedRows.Item(i).Cells.Item(16).Value = System.DBNull.Value
Next
MsgBox("TerritoryID reset. Use Save button to refresh your view")
Else
MsgBox("Highlight a row in the Householder list before attempting to delete")
End If
End Sub
Any suggestions? ALso, i tried to change the hard coded value of 16 to the actual name of the field but it doesn't recognize it. What am I missing?
Thanks.