在运行时转换DataGridView Cell类型

Kil*_*are 5 c# datagridview winforms

我的datagridview有一个复选框列,该列仅对其显示的数据中的某些记录有效.对于复选框无效的记录,我希望不显示任何内容 - 例如空白文本框.

因此,我需要在运行时动态地将单元格类型从复选框单元格更改为文本框单元格.我不能简单地更改列数据类型,因为列需要混合使用textbox和checkbox单元格类型.

到目前为止,我有以下代码.

 this.deviceList1.DeviceGrid[colIndex, rowIndex] = new KryptonDataGridViewTextBoxCell()
 this.deviceList1.DeviceGrid[colIndex, rowIndex].ReadOnly = true;
Run Code Online (Sandbox Code Playgroud)

如果这会生成DataGridView数据错误:

System.FormatException:单元格的格式化值类型错误.

Kil*_*are 6

对它进行排序.真的很简单.解决方案是确保Value属性具有适当的值.即它需要设置为字符串值.

this.deviceList1.DeviceGrid[colIndex, rowIndex] =  new KryptonDataGridViewTextBoxCell()
this.deviceList1.DeviceGrid[colIndex, rowIndex].ReadOnly = true;
this.deviceList1.DeviceGrid[colIndex, rowIndex].Value = "";
Run Code Online (Sandbox Code Playgroud)