将 Datagrid 列设置为在 运行 时间内只读

Setting a Datagrid Column to read only during run time

我有一个数据网格,而不是数据网格视图,如果单选按钮是否被选中,我想将其中的列设置为只读。

所以我从 sql 查询动态定义列:

Dim bool_col As New FormattableBoolColumn 
bool_col.HeaderText = "Bool Colunm"
bool_col.MappingName = "bool_col"

表单上还有两个单选按钮,我们称它们为 A 和 B。
选中 A 后,我想将 bool_col 设置为只读为真。 选中 B 后,我想将 bool_col 设置为只读是 false。

如果还需要什么,请告诉我。我正在使用 Click 事件,但我不知道如何在 Datagrid 中找到该列并将其设置为只读。整个下午都在尝试这样做,并搜索了我能想到的所有东西,但没有成功。 不幸的是,我无法将其更改为 datagridview。项目的时间和金钱限制禁止这样做。

提前致谢!

创建列时可以添加检查:

bool_col.ReadOnly = RadioButtonA.Checked

因此,如果选中 A,则列的只读 属性 为真,否则为假。

现在假设您的单选按钮在一个组中,因此一次只能选中两个单选按钮中的一个。

如果单选按钮不在一个组中,则使用:

If RadioButtonA.Checked Then
bool_col.ReadOnly = true
else if RadioButtonB.Checked Then
bool_col.ReadOnly = false
End If