CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    5

    Resetting the CheckBox value in a DataGridView?

    Below is the code that I am using to reset the CheckBox value in a column within my DGV. My problem is that if the checkbox is already checked and the user tries to uncheck it...it won't actually be removed until the user clicks somewhere else in the DGV or checks another box. I'm not sure why this is happening. Obviously, I'm missing something else. Please help!

    Thanks!

    Code:
     Private Sub dgvBuild_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvBuild.CellContentClick
            Try
                Select Case e.ColumnIndex
                    Case 6
                        dgvBuild.ClearSelection()
                        If dgvBuild.Rows(e.RowIndex).Cells(6).Value = True Then
                            Dim answer As Integer = MessageBox.Show("Continue with Deletion?", "User Notification", MessageBoxButtons.YesNo)
    
                            If answer = 6 Then
                                If WIPD.DeleteWIP_Detail(dgvBuild.Rows(e.RowIndex).Cells(1).Value) Then
                                    dgvBuild.Rows.RemoveAt(e.RowIndex)
                                    dgvBuild.Rows.Remove(dgvBuild.CurrentRow)
                                    ReCalculateTotals(1)
                                End If
                            Else       'Uncheck the checkbox                         
                                dgvBuild.Rows(e.RowIndex).Cells(6).Value = False                        
                            End If
                        End If
                End Select
            Catch ex As Exception
                strErrMsg = "frmProductBuild/dgvBuild_CellContentClick() - " & ex.Message
                MessageBox.Show(strErrMsg, "System Notification", MessageBoxButtons.OK)
            End Try
        End Sub
    Blake

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Resetting the CheckBox value in a DataGridView?

    A silly suggestion. I would test for the column, instead of the row, as you have done :
    Code:
     If dgvBuild.Rows(e.RowIndex).Cells(6).Value = True Then
    I would replace that with something like :

    Code:
    If e.ColumnIndex = DataGridView1.Columns("WHATEVER HEADING").Index Then
    I did a small test, and seems to work fine...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured