在DataGridView上选中/未选中和禁用复选框 [英] Check/Unchecked And Disabled Check boxes on DataGridView

查看:93
本文介绍了在DataGridView上选中/未选中和禁用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows应用程序的DataGridView上显示已选中"或未选中和已禁用"复选框.我试图继承DataGridViewCheckBoxColumn和DataGridViewCheckBoxCell并尝试覆盖它的Paint(),但是由于网格包含另一个列且包含5列复选框,所以无法在所需位置绘制复选框.有人可以向我建议更简单的解决方案吗?

I am trying to display Checked OR UnChecked AND Disabled check boxes on DataGridView in windows application. I tried to inherit DataGridViewCheckBoxColumn and DataGridViewCheckBoxCell and tried to override Paint() of it but could not get check boxes painted at desired locations since grid is containignother column also with 5 column of check boxes. Can anyone suggest me the easier solution?

推荐答案

在我的情况下,我将DatagridView与列表绑定.
列表的每个元素都继承INotifyPropertyChanged.因此,使用这种方法,我直接在列表中进行了更改:

私有void CheckTheBoxes()
{
如果(CheckAll == true)
{
foreach(ODBCList中的ODBC o)
{
o.Check = true;
}

tmpControl = false;

}
其他
{
foreach(ODBCList中的ODBC o)
{
o.Check = false;
}

tmpControl = true;
}
}
In my case, I bind the DatagridView with a List.
Each element of the list inherits INotifyPropertyChanged. So, using this way, I made the change directly in the list:

private void CheckTheBoxes()
{
if (CheckAll== true)
{
foreach (ODBC o in ODBCList)
{
o.Check= true;
}

tmpControl= false;

}
else
{
foreach (ODBC o in ODBCList)
{
o.Check= false;
}

tmpControl= true;
}
}


这篇关于在DataGridView上选中/未选中和禁用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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