开发者

Working with Checkbox column in DataGrid in Winforms project

开发者 https://www.devze.com 2023-01-01 02:37 出处:网络
I have a checkbox column, and it is开发者_StackOverflow working just as intended. How do I \"get\" the selected rows ?

I have a checkbox column, and it is开发者_StackOverflow 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.


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);
    }    
}


Solved it through:

foreach (DataGridViewRow item In DataGridName.Rows)
{

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

}
0

精彩评论

暂无评论...
验证码 换一张
取 消