开发者

Working with Checkbox column in DataGrid in Winforms project

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜