VB.net DataGridView check box cells

Murray Brown
Murray Brown used Ask the Experts™
on
Hi
I am using the following code to see if the cells in a DataGridView row are checked and
it seems to detect some but not others being checked.
Is there a better way to do this?      

 Dim D4 As DataGridView = Globals.ThisAddIn.oBOTTOM.DataGridView4
        Dim R4 As DataGridViewRow = Globals.ThisAddIn.oBOTTOM.DataGridView4.Rows(0)
        For i = 0 To D4.ColumnCount - 1
            If R4.Cells(i).Value = True Then
                MsgBox("checked " & CStr(i))
            End If
        Next
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Here goes, easier to follow iteration (and read at a later date)
For Each x As DataGridViewRow In Me.DataGridView1.Rows
    For Each y As DataGridViewCell In x.Cells
       If TypeOf y Is DataGridViewCheckBoxCell AndAlso CType(y, DataGridViewCheckBoxCell).Value = True Then
            MessageBox.Show("Checked " & y.ColumnIndex)
       End If
    Next
Next

Open in new window

Murray BrownASP.net/VBA/VSTO Developer

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial