现在的位置: 首页 > 综合 > 正文

C# 获取DataGridView中的复选框

2013年02月06日 ⁄ 综合 ⁄ 共 277字 ⁄ 字号 评论关闭

如图:

根据选中的复选框获得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()));

抱歉!评论已关闭.