C# Windows DataGridView 判断CheckBox 选取的方法

单行选中

foreach (DataGridViewRow dr in this.dataGridView1.Rows)
            {
                try
                {
                    //DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells[0];
                    //if ((bool)cbx.FormattedValue)
                    if(dr.Cells[0].Selected)
                    {
                        arrShiftCode.Add(dr.Cells[1].Value);
                        arrShiftGroup.Add(dr.Cells[2].Value);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

复制代码
多行选中
foreach (DataGridViewRow dr in this.dataGridView1.Rows)
            {
                try
                {
                    DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells[0];
                    if ((bool)cbx.FormattedValue)
                    {
                        arrShiftCode.Add(dr.Cells[1].Value);
                        arrShiftGroup.Add(dr.Cells[2].Value);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

posted on 2015-03-15 16:26  连一粝  阅读(347)  评论(0编辑  收藏  举报

导航