c# - 如何禁用 DataGridView CheckBox 列中的特定复选框单元格

标签 c# winforms datagridview

我有一个带有 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/

相关文章:

c# - 名称函数在当前上下文中不存在 C# 错误

c# - WinForms 应用程序的体系结构?

vb.net - 如何解决幻像断点?

c# - 在 Designer 中使用时自定义 DataGridView 列重复

c# - 将 DataTable 中的列值从 byte[] 转换为 String

c# - C#调用AS400程序,从QTEMP中选择文件

c# - 使用 httpClient 发布 json 未到达服务器

c# - 如何使用 SQL Server 创建自定义 ASP.NET 身份提供程序?

c# - 如何读取屏幕分辨率 - 并更改此分辨率?

c# - 类型名称 'DatasetTableAdapters' 在类型中不存在