mercredi 23 décembre 2015

Find rows with CheckBox checked DataGridView

I put some code in to find what checkboxes have been checked in my DataGridView, but for some reason this isn't working.

I have looping through the rows in the DataGridView:

For Each row As DataGridViewRow In dgv_assets.Rows

Next

Then in here i have casted the first column as a DataGridViewCheckBoxCell:

For Each row As DataGridViewRow In dgv_assets.Rows

    Dim chk As DataGridViewCheckBoxCell = DirectCast(row.Cells(0), DataGridViewCheckBoxCell)

Next

Then I am checking for all the checkboxes that have been checked:

For Each row As DataGridViewRow In dgv_assets.Rows

    Dim chk As DataGridViewCheckBoxCell = DirectCast(row.Cells(0), DataGridViewCheckBoxCell)

    If chk.Value = chk.TrueValue Then
        MessageBox.Show("Checked")
    End If

Next

For some reason even if the checkboxes are checked or unchecked they all hit the MessageBox.




Aucun commentaire:

Enregistrer un commentaire