CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    Datagridview Checkbox

    Hi all,

    I have the following codes:

    Code:
        Private Sub dgCustomerPackage_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCustomerPackage.CellClick
            If TypeOf dgCustomerPackage.CurrentCell Is DataGridViewCheckBoxCell Then
                If 1 + 1 = 2 Then
                    dgCustomerPackage.CurrentRow.Cells("colchkSelect").Value = 0
                Else
                    dgCustomerPackage.CurrentRow.Cells("colchkSelect").Value = 1
                End If
            End If
        End Sub
    I am wondering why my "colchkSelect" will be checked even though the above codes showing that it should not be checked when the cell click event?

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Datagridview Checkbox

    Only if you click the cell. But, you need to check the type in the IF condition. Your code will always be 0 because 1+1 is 2
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2009
    Location
    NW USA
    Posts
    173

    Re: Datagridview Checkbox

    I don't think the CheckBox.Value is what you want. You will need to put a checkbox on a form, catch the event, put a break in the event and look at the checkbox to see what actually turns true when the box is checked. I think it is Checked. So if you put dgCustomerPackage.CurrentRow.Cells("colchkSelect").Checked = False I think you will get what you want.

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