Marcelo
Marcelo

Reputation: 3391

Working with Checkbox column in DataGrid in Winforms project

I have a checkbox column, and it is working just as intended.

How do I "get" the selected rows ?

I'd like to get the ones that are checked and run a method using another field of the same row.

Upvotes: 4

Views: 1292

Answers (2)

Michael Eakins
Michael Eakins

Reputation: 4179

I believe the answer would look something like:

foreach (DataGridViewRow item in DataGridName.Rows) 
{
    if (((bool)(item.Cells["name_of_column"].Value)) == true)
    {
        MyMethod(item.Cells["name_od_the_other_field"].Value);
    }    
}

Upvotes: 7

Marcelo
Marcelo

Reputation: 3391

Solved it through:

foreach (DataGridViewRow item In DataGridName.Rows)
{

    If (item.Cells(0).Value)
    {
        MyMethod(item.Cells(0).Value);
    }   

}

Upvotes: 2

Related Questions