locked
Checkbox column of datagridview RRS feed

  • Question

  • Hi All,
    I have a datagridview with 2 columns, one is text box and another one is check box column. My problem is that when i check or uncheck on cell of check box column i just want to show a value of this cell but it show opposit to it real value, it mean that when i check on this cell its value is false so this result is not correct . So can you tell me a event that match my issue problem.

    Thanks for helps
    Pitou
    Thursday, March 11, 2010 12:18 PM

Answers

  • Right Click on DatagridView
    Click on Properties
    Look for Columns
    Edit Collection
    Look for CheckBox Column
    Check Values for the following Column Properties:
       FalseValue
       IndeterminateValue
       TrueValue


    Then check the value in the DatagridView Click Event as follows:
    (dgv is the Datagridview name i used)

     

    Private Sub dgv_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentClick

    MsgBox(dgv.CurrentRow.Cells(1).EditedFormattedValue)

     

    End Sub

    • Proposed as answer by Alex Liang Monday, March 15, 2010 5:02 PM
    • Marked as answer by Alex Liang Wednesday, March 17, 2010 4:05 AM
    Saturday, March 13, 2010 8:17 PM
  • Hi PitouMathCom,

    You can set the cell's value in the first column to the corresponding cell's value in the check box column in datagridview's CellContentClick event handler, just as Andy showed. For more detail, you can do something like this:

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If e.RowIndex >= 0 And e.RowIndex < DataGridView1.RowCount Then
            If e.ColumnIndex = 1 Then
                DataGridView1.Rows(e.RowIndex).Cells(0).Value = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).EditedFormattedValue
            End If
        End If
    End Sub
    


    Best regards,
    Alex Liang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Alex Liang Wednesday, March 17, 2010 4:05 AM
    Monday, March 15, 2010 5:09 PM
  • Thanks Andy3B.
     
    Pitou
    • Marked as answer by Pitou H Thursday, March 18, 2010 1:12 AM
    Thursday, March 18, 2010 1:11 AM

All replies

  • Right Click on DatagridView
    Click on Properties
    Look for Columns
    Edit Collection
    Look for CheckBox Column
    Check Values for the following Column Properties:
       FalseValue
       IndeterminateValue
       TrueValue


    Then check the value in the DatagridView Click Event as follows:
    (dgv is the Datagridview name i used)

     

    Private Sub dgv_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentClick

    MsgBox(dgv.CurrentRow.Cells(1).EditedFormattedValue)

     

    End Sub

    • Proposed as answer by Alex Liang Monday, March 15, 2010 5:02 PM
    • Marked as answer by Alex Liang Wednesday, March 17, 2010 4:05 AM
    Saturday, March 13, 2010 8:17 PM
  • Hi PitouMathCom,

    You can set the cell's value in the first column to the corresponding cell's value in the check box column in datagridview's CellContentClick event handler, just as Andy showed. For more detail, you can do something like this:

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
        If e.RowIndex >= 0 And e.RowIndex < DataGridView1.RowCount Then
            If e.ColumnIndex = 1 Then
                DataGridView1.Rows(e.RowIndex).Cells(0).Value = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).EditedFormattedValue
            End If
        End If
    End Sub
    


    Best regards,
    Alex Liang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Alex Liang Wednesday, March 17, 2010 4:05 AM
    Monday, March 15, 2010 5:09 PM
  • Thanks Andy3B.
     
    Pitou
    • Marked as answer by Pitou H Thursday, March 18, 2010 1:12 AM
    Thursday, March 18, 2010 1:11 AM