views:

243

answers:

2

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.

+1  A: 

Solved it through:

foreach (DataGridViewRow item In DataGridName.Rows)
{

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

}
MarceloRamires
Please accept your solution otherwise it pops up in unanswered list.
agsamek
+6  A: 

I am not as familiar with C# as I am with VB.NET in which I would use

For Each row As DataGridViewRow In dgv.rows If row.Cells("name_of_column").Value = True Then Call MyMethod(row.Cells("name_of_column").Value) End If Next

I believe the answer would look something like:

foreach (DataGridViewRow item In DataGridName.Rows) 
{ 

    If (item.Cells("name_of_column").Value = TRUE) 
    { 
        MyMethod(item.Cells("name_of_column").).Value); 
    }    

} 

or it may be

foreach (DataGridViewRow item In DataGridName.Rows) 
{ 

    If (item.Cells("name_of_column").Value == TRUE) 
    { 
        MyMethod(item.Cells("name_of_column").).Value); 
    }    

} 

in C#.

Michael Eakins