在C#.net中检查DataGridViewCheckBoxColumn [英] Check DataGridViewCheckBoxColumn in C#.net

查看:47
本文介绍了在C#.net中检查DataGridViewCheckBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用C#.net开发Windows应用程序...我有一个带3个DataGridViewCheckBoxColumn(checkbox1,checkbox2,checkbox3)的datagridview..

在这里,我想取消选中剩下的2列,而我又选中了一个特定的列..例如,第一,我选中checkbox1,然后更改为checkbox2,那时候我需要自动取消选中checkbox1列,反之亦然.....

帮帮我吧!!!!!!!!!

Hi Guys,

I am developing windows application using C#.net...In that I have one datagridview with 3 DataGridViewCheckBoxColumn (checkbox1,checkbox2,checkbox3)..

here i want to uncheck the remainining 2 colums while i checked one particular column..for eg,1st i check checkbox1 and i change to check checkbox2,that time i need to uncheck checkbox1 column automatically and viceversa........

Help me out guys!!!!!!!!!

推荐答案

在单击控件的 CheckedChanged 事件中执行此操作,您还可以获得单击控件的当前行,您也可以从同一行中找到其余控件.
do it in CheckedChanged event of clicked control, you can also get current row of the clicked control, and also you can find the remaining controls from the same row.


最后,我得到了解决方案....

在CellValidating事件上编写以下代码,

Finally i got solution for this....

write following code on CellValidating event,

int column = e.ColumnIndex;
            int row = e.RowIndex;
            if (column == 2)
            {
                DataGridViewCheckBoxCell c = dgv1[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
                if (c != null)
                {
                    string a = e.FormattedValue.ToString();
                    if (a == "True")
                    {                       
                        dgv1.Rows[row].Cells["column2"].Value = false;
                        dgv1.Rows[row].Cells["column3"].Value = false;
                    }
                    else
                    {                        
                        dgv1.Rows[row].Cells["column1"].Value = false;
                        dgv1.Rows[row].Cells["column2"].Value = false;
                        dgv1.Rows[row].Cells["column3"].Value = false;
                    }
                }
            }



重复其余列的代码........



repeat the code for remaining columns........


DataTable dt = new DataTable()
foreach(dt.Rows中的DataRow行)
{
如果(row ["gridviewcheckboxcolumnname"].ToString()==真")
{
//您的代码
}
}
DataTable dt = new DataTable()
foreach (DataRow row in dt.Rows)
{
if (row["gridviewcheckboxcolumnname"].ToString() == "True")
{
//your Code
}
}


这篇关于在C#.net中检查DataGridViewCheckBoxColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆