在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;
}
}