代码改变世界

C# 获取DataGridView中的复选框

2011-12-03 21:33  Andrew.Wangxu  阅读(601)  评论(0编辑  收藏  举报

如图:

 

根据选中的复选框获得ID。

代码如下:

List<string> ids = new List<string>();  
foreach (DataGridViewRow row in dgrd_Human.Rows)
{
if (row.Cells["selected"].Value != null)
{
if(row.Cells["selected"].Value.ToString() == "True")
ids.Add(row.Cells[1].Value.ToString());
}
}
MessageBox.Show(string.Join(",", ids.ToArray()));


参考:http://www.wxzzz.com/?id=48