Hi,

I have 2 checkboxes in a datagridview
I added this code

Private Sub dgSO_CurrentCellDirtyStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgSO.CurrentCellDirtyStateChanged
        If dgSO.IsCurrentCellDirty Then
            dgSO.CommitEdit(DataGridViewDataErrorContexts.Commit)
        End If
    End Sub

and when user click the checkbox, i used this code

Private Sub dgSO_CellContentClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgSO.CellContentClick
        If dgSO.CurrentRow.Cells("Notching").Value = True Then
            MsgBox("notching")
            Exit Sub
        ElseIf dgSO.CurrentRow.Cells("Arc-Edge").Value = True Then
            MsgBox("Arc-Edge")
            Exit Sub

        End If

    End Sub

the problem is when I click the arc edge and the notching is currently checked, it still shows the MsgBox("notching") since it detected that it is checked

how will i do the approach that only shows the message of the checkbox that is checked by user?

thanks

You can try it

 If TypeOf dgSO.CurrentCell.OwningColumn Is DataGridViewCheckBoxColumn Then

            Dim chkcell As DataGridViewCheckBoxCell = CType(dgSO.CurrentCell, DataGridViewCheckBoxCell)

            If chkcell.EditingCellValueChanged Then
                If chkcell.EditingCellFormattedValue = True Then
                    MessageBox.Show(chkcell.OwningColumn.HeaderText)
                End If
            End If

 End If

Hi,

Thanks for the reply. I tried your code under cellcontentclick but nothing happened. no message showed.
One thing more, How about there will be different actions for each checkbox, in your code how will I specify which checkbox will do the specific operation?

I tried changing this

Dim chknotch As DataGridViewCheckBoxCell = CType(dgSO.CurrentCell, DataGridViewCheckBoxCell)

to

Dim chknotch As DataGridViewCheckBoxCell = CType(dgSO.CurrentRow.Cells("Notching"), DataGridViewCheckBoxCell)

still no luck

You must have to remove this event handler dgSO.CurrentCellDirtyStateChangedto get result.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.