打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
DataGridView的复选框列的选中事件:DataGirdCheckBoxColumn...

DataGridView的复选框列的选中事件:DataGirdCheckBoxColumn 列 选中 事件。

       今天在winform下使用DataGridView时,使用了checkbox列。一般我们可以通过一个按钮的单击事件中,来判断该列是否被选中。但这样似乎不太人性化。因此改为当checkbox被选中时,执行任务。
       可别小看了这个问题。我试了很多的datagridview事件,比如 cellClick CellContentChanged 等事件,要不就是无法扑捉,要不就是得到的值为选中前的值:false 。
   
   当然,最后无意找到了正确的事件:cellContentClick 事件。在该事件中可得知选中前后的值,代码如下:
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        
{
            
if (e.ColumnIndex == 3 && Convert.ToInt32(tbCpiName.Tag)>0 )//当单击复选框,同时处于组合编辑状态时
            {
                DataGridViewCell cell 
= dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
                
bool ifcheck1 = Convert.ToBoolean(cell.FormattedValue);
                
bool ifcheck2 = Convert.ToBoolean(cell.EditedFormattedValue);

                
if (ifcheck1 != ifcheck2)
                
{
                    BCItem bcitem 
= new BCItem();
                    bcitem.B_bciID 
= Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["bciID"].Value);
                    bcitem.C_CpiID 
= Convert.ToInt32(tbCpiName.Tag);

                    
if (ifcheck2)//将该项目与组合关联
                    {
                        bllcp.AddCompageAndItem(bcitem);
//关联
                    }

                    
else
                    
{
                        bllcp.DeleteCompageAndItem(bcitem);
//取消关联
                    }

                }

            }

        }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
DataGridViewCheckBoxColumn使用简单说明
DataGridView 冻结列或行
winform DataGridView中设置CheckBox全选和取消全选
DataGridView控件用法(一)绑定数据
datagridview 的DataGridViewComboBoxColumn事件
c# 如何用datagridview获取选中的单元格内容
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服