Tinshooter
Member
- Joined
- Oct 6, 2011
- Messages
- 6
- Programming Experience
- 1-3
Hey guys, Here is my issue, I have a delete button in a datagridview. The button works fine however when there is nothing to delete it throws an index out of range exception. Now I know for a fact people are going to click that button even though there is nothing there so I guess what I need help with is error handling; I am presuming the best course of action is going to be a try/catch but I am not sure how to do it. My code is as follows, any help would be greatly appreciated, oh and if I am posting this in the wrong place I apologize.
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex <> 7 Then
Exit Sub
End If
VoicemailDataSet.Message.Rows(DataGridView1.CurrentRow.Index).Delete()
MessageTableAdapter.Update(VoicemailDataSet.Message)
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.ColumnIndex <> 7 Then
Exit Sub
End If
VoicemailDataSet.Message.Rows(DataGridView1.CurrentRow.Index).Delete()
MessageTableAdapter.Update(VoicemailDataSet.Message)
End Sub