Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 687
Marcelo Avatar asked Jan 23 '23 01:01

Marcelo


2 Answers

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);
    }    
}
like image 98
Michael Eakins Avatar answered Jan 24 '23 14:01

Michael Eakins


Solved it through:

foreach (DataGridViewRow item In DataGridName.Rows)
{

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

}
like image 45
Marcelo Avatar answered Jan 24 '23 14:01

Marcelo