troubleshooting Question

Datagrideview Checkbox Column - Index Error

Avatar of vwalla
vwalla asked on
Visual Basic.NET
24 Comments1 Solution847 ViewsLast Modified:
I get an index out of range error when I do the following on my check box column:

1. Select the 2nd from last record checkbox. The bindingsource filters it out of the datagridview.
2. The last row is automatically slelected. When I click it again I get this error: (see attached image)

Here is my code:


Code:
Private Sub TblShapeListDataGridViewUnBound_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TblShapeListDataGridViewUnBound.CellClick
        Try
            If Not e.RowIndex = -1 Then
                If e.ColumnIndex = 2 Then
                    Dim chkFired As DataGridViewCheckBoxCell = CType((Me.TblShapeListDataGridViewUnBound(2, e.RowIndex)), DataGridViewCheckBoxCell)
                    If chkFired.GetEditedFormattedValue(e.RowIndex, DataGridViewDataErrorContexts.CurrentCellChange) = True Then
                        chkFired.Value = False
                        Me.TblShapeListDataGridViewUnBound(5, e.RowIndex).Value = DBNull.Value
                        Me.TblShapeListDataGridViewUnBound(6, e.RowIndex).Value = DBNull.Value
                    Else
                        chkFired.Value = True
                        Me.TblShapeListDataGridViewUnBound(5, e.RowIndex).Value = OCNumber
                        Me.TblShapeListDataGridViewUnBound(6, e.RowIndex).Value = OCFileName
                    End If
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try

Ami Going about this all wrong??

Thanks,

Vwalla
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 24 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros