2011-05-17 35 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事件處理程序,並繪製在控制空方。這是一種哈克,我敢肯定還有其他選擇,但它的工作原理。

相關問題