• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

DGV CheckBoxColumn - Uncheck cell by code.

Experts, the code below runs all the way through (no error messages), but Lines 9 and 10 (for a checkbox column) don't work as intended. I set a breakpoint at Line 9 and a mouse-over of both lines shows "Item - In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user."  I've tried several changes, but haven't hit the solution. What am I missing?


Private Sub dgv1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv1.CurrentCellDirtyStateChanged

        If dgv1.CurrentRow.Cells(4).Selected = True Then
            If dgv1.CurrentRow.Cells(4).EditedFormattedValue.ToString = "True" Then
                If Not IsDBNull(dgv1.CurrentRow.Cells(1)) Then
                    tbCode = dgv1.CurrentRow.Cells(1).Value   'Public Shared variable
                    frmDGVPrint1.ShowDialog()
                    If frmDGVPrint1.Uncheck = True Then
                        dgv1.CurrentRow.Cells(4).Value = False
                        dgv1.CurrentRow.Cells(4).Selected = False
                        frmDGVPrint1.Uncheck = False
                        Exit Sub
                    End If
                Else
                    MessageBox.Show("Order Code not entered.", "MISSING DATA")
                    Exit Sub
                End If
            End If
        End If
    End Sub

Open in new window

0
Tim313
Asked:
Tim313
1 Solution
 
CodeCruiserCommented:
Try changing

 dgv1.CurrentRow.Cells(4).Value = False

to

 CType(dgv1.CurrentRow.Cells(4), DataGridViewCheckboxCell).Value = False
0
 
Tim313Author Commented:
CodeCruiser, I tried your suggestion, but ended up with the same problem "Item - In order to evaluate...". However, this time I noticed an icon (circle w/ two clockwise arrows inside) between "Item" and "In order to evaluate..." . Thinking this may indicate a circular reference since the event is "dgv1_CurrentCellDirtyStateChanged", I changed:

CType(dgv1.CurrentRow.Cells(4), DataGridViewCheckboxCell).Value = False   to
CType(dgv1.CurrentCell, DataGridViewCheckboxCell).Value = False

which removed the "Item - In order to evaluate..." and allowed the cell value to change from True to False. However, the cell's "EditedFormattedValue" remained True. I found that the cell was still in edit mode, so I added the line "dgv1.EndEdit()". to solve that problem. Eventually I ended up with the code below that seems to work the way I need.

I'm going to award you the points because although your code line resulted in the same problem as mine, it did show me where the problem was and allowed me to reach a solution.

Thanks much!
Private Sub dgv1_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv1.CurrentCellDirtyStateChanged

        If dgv1.CurrentRow.Cells(4).Selected = True Then
            dgv1.CurrentRow.Cells(4).Selected = False
            If dgv1.CurrentRow.Cells(4).EditedFormattedValue.ToString = "True" Then
                If Not IsDBNull(dgv1.CurrentRow.Cells(1)) Then
                    tbCode = dgv1.CurrentRow.Cells(1).Value   'Public Shared variable
                    dgv1.EndEdit()
                    frmDGVPrint1.ShowDialog()
                    If frmDGVPrint1.Uncheck = True Then
                        dgv1.CurrentCell.Value = False
                        dgv1.CurrentCell.Selected = True
                        frmDGVPrint1.Uncheck = False
                        Exit Sub
                    End If
                Else
                    MessageBox.Show("Order Code not entered.", "MISSING DATA")
                    Exit Sub
                End If
            End If
        End If
    End Sub

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now