欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

DataGridView中CheckBox实现某一列单选

程序员文章站 2024-03-04 21:44:00
复制代码 代码如下:private void dgvchannel_cellclick(object sender, datagridviewcelleventargs e...
复制代码 代码如下:

private void dgvchannel_cellclick(object sender, datagridviewcelleventargs e)
        {
            if (e.columnindex == -1 || e.rowindex == -1) return;
            int x = dgvchannel.currentcell.columnindex;//获取鼠标的点击列
            if (x == 0)//点击第一列是单选。
            {
                for (int i = 0; i < dgvchannel.rows.count; i++)
                {
                    datagridviewcheckboxcell checkcell = (datagridviewcheckboxcell)dgvchannel.rows[i].cells[0];
                    checkcell.value = false;
                }
                datagridviewcheckboxcell ifcheck = (datagridviewcheckboxcell)dgvchannel.rows[e.rowindex].cells[0];
                ifcheck.value = true;
            }
        }