datagridview 的一些使用小技巧

来源:互联网 发布:win10下安装linux 编辑:程序博客网 时间:2024/06/05 04:36

在DataGridView中获得DataGridViewCheckBoxColumn的状态

当我们选中该Cell后,第1时间得到的该值为:
dgView1.Rows(i).Cells(1).Value = False

 

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            //MessageBox.Show(dataGridView1.Columns[e.ColumnIndex].CellTemplate.ToString());
            if (dataGridView1.RowCount > 0 && e.RowIndex > -1)
            {
                string action = dataGridView1.Columns[e.ColumnIndex].Name;

                if (action == "BtnDel")
                {
                    string ID = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    MessageBox.Show(ID);
                }
                if (action == "isUse")
                {
                    string value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                    MessageBox.Show(value);
                }
            }
        }

 

if (MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }