DataGridViewComboBoxCell.ReadOnly = true,但仍可以更改所选值 [英] DataGridViewComboBoxCell.ReadOnly = true, but can still change the selected value
问题描述
我在C#中使用DataGridView和DataGridViewComboBoxCell感到困难(Visual Studio 2013,.NET 4.5.1)
I am strugling with a problem with DataGridView and DataGridViewComboBoxCell in C# (Visual Studio 2013, .NET 4.5.1)
DataGridView具有3列,其中DataGridViewComboBoxColumn和3
The DataGridView has 3 columns with DataGridViewComboBoxColumn and 3 columns with DataGridViewTextBoxColumn.
DataGrid绑定到DataTable
The DataGrid is bound to a DataTable
我需要分别为每个单元格:
I need to set the readonly property individually for each cell:
对于现有行:
只有最后一个单元格(DataGridViewTextBoxCell)才是可编辑的。
For existing rows: Only the last cell (DataGridViewTextBoxCell) shall be editable.
添加新行时,除两个文本框单元格外的所有单元格均应可编辑。
When adding new row, all cells except two textbox cells shall be editable.
我的问题是,即使ReadOnly,最终用户仍然可以更改DataGridViewComboBoxCells的选择= true;
My problem is that the end user can still change the selection of the DataGridViewComboBoxCells even when ReadOnly = true;
在DataGridViewTextBoxCells上设置ReadOnly = true很好
Setting ReadOnly=true on DataGridViewTextBoxCells works fine
在DataGridViewComboBoxCell上设置ReadOnly = true无效。
写出ReadOnly属性时,它返回true,但单元格仍可编辑。
Setting ReadOnly=true on DataGridViewComboBoxCell has no effect. When writing out the ReadOnly property, it returns true, but the cell is still editable.
推荐答案
DataGridView.CellBeginEdit
中的类似代码:
If Not <your code to verify if you are adding a new row> Then
If Not YourDataGridView.Columns(e.ColumnIndex).Name = "EditableColumnName" Then
e.Cancel = True
End If
End If
这篇关于DataGridViewComboBoxCell.ReadOnly = true,但仍可以更改所选值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!