• 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);//取消关联
                }
            }
        }
    }

    http://www.cnblogs.com/lyamlf123/articles/1147292.html

  • 相关阅读:
    windows下安装mysql(mysql-installer-community-5.6.10.1)
    mysql安装
    Full GC为什么那么慢?为什么老年代垃圾回收效率比新生代低很多?为什么Minor gc速度比Major GC慢?
    tomcat和HTTP(r equest response )
    response和request
    一次完整的Http请求过程
    servlet
    java泛型
    数据库索引的实现原理
    终端打印
  • 原文地址:https://www.cnblogs.com/emanlee/p/1528072.html
Copyright © 2020-2023  润新知