2011-05-17 33 views
5

我的datagridview有一个复选框列,它只对它显示的数据中的某些记录有效。对于复选框无效的记录,我希望不显示任何内容 - 例如空白文本框。在运行时转换DataGridView单元格类型

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

到目前为止我的代码如下。

this.deviceList1.DeviceGrid[colIndex, rowIndex] = new KryptonDataGridViewTextBoxCell() 
this.deviceList1.DeviceGrid[colIndex, rowIndex].ReadOnly = true; 

Howver这会产生一个DataGridView数据错误:

System.FormatException: Formatted value of the cell has a wrong type.

+0

啊,解决方法是确保Value属性被赋予一个适当的值。即它需要设置为一个字符串值。 this.deviceList1.DeviceGrid [colIndex,rowIndex] .Value =“”; – Kildareflare 2011-05-17 16:13:22

回答

6

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

this.deviceList1.DeviceGrid[colIndex, rowIndex] = new KryptonDataGridViewTextBoxCell() 
this.deviceList1.DeviceGrid[colIndex, rowIndex].ReadOnly = true; 
this.deviceList1.DeviceGrid[colIndex, rowIndex].Value = ""; 
0

你可以使用在该小区OnPaint事件处理程序,并绘制在控制空方。这是一种哈克,我敢肯定还有其他选择,但它的工作原理。

相关问题