datagridview 的一些使用小技巧

本文介绍了在Windows应用中使用DataGridView时,如何在CellClick事件中获取DataGridViewCheckBoxColumn的选择状态以及如何获取选中行的相关数据。通过示例代码展示了在用户点击删除按钮时,显示确认对话框,并在特定列(如'isUse'列)被点击时,弹出选中单元格的值。
摘要由CSDN通过智能技术生成

在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.RowInde

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值