我有一个带有 DataGridView 控件的 winForm。它包含 5 列,其中一列是 CheckBox 列。我想根据同一行另一列中存在的值启用/禁用此列的复选框单元格。
我可以使用 DisabledCheckBoxCell 禁用整个列
但它会使整个列处于禁用状态。
这是 DataGridView 的一个片段,
来源栏目 |目标列
真实 |启用
真实 |启用
假 |禁用
有没有人知道如何在 .Net 中实现这一点。
最佳答案
维杰,
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;
}
}
关于c# - 如何禁用 DataGridView CheckBox 列中的特定复选框单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10332715/