我有一个带有 DataGridView 控件的 winForm。它包含 5 列,其中一列是 CheckBox 列。我想根据同一行另一列中存在的值启用/禁用该列的复选框单元格。
我可以使用禁用整个列
但它使整个列处于禁用状态。
这是 DataGridView 的片段,
来源专栏 |目的地栏
正确 |已启用
正确 |已启用
假 |残疾人
有谁知道如何在.Net 中实现这一点。
Vijay,
DataGridViewCheckBoxColumn 没有名为“disabled”的属性,因此通过更改复选框的样式,可以使其看起来像是被禁用的。看下面的代码。
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
if (e.RowIndex == 1)
{
DataGridViewCell cell=dataGridView1.Rows[e.RowIndex].Cells[0];
DataGridViewCheckBoxCell chkCell = cell as DataGridViewCheckBoxCell;
chkCell.Value = false;
chkCell.FlatStyle = FlatStyle.Flat;
chkCell.Style.ForeColor = Color.DarkGray;
cell.ReadOnly = true;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)