我有一個從數據集填充的datagridview。如何將datagridview單元格樣式從默認文本框更改爲vb.net中的組合框?
填充後,如果用戶單擊一行,最後一列應該從文本框更改爲組合框。
我使用vb.net 2010
在Datagridview1 CellClick事件:
With DataGridView1
If .Rows.Count = 0 Then Exit Sub
i = Datagridview1.currentrow.index
Dim gridComboBox As New DataGridViewComboBoxCell
gridComboBox.Items.Add("A") 'Populate the Combobox
gridComboBox.Items.Add("B") 'Populate the Combobox
gridComboBox.Items.Add("C") 'Populate the Combobox
.Item(8, i) = gridComboBox
End With
但是,這將導致一個錯誤:如果情況是不可行的
The following exception occurred in DataGridView:
System.Argument.Exception: DataGridViewComboBoxCell value is not valid.
To replace this default dialog please handle the DataError event.
,我希望在填充數據集中的數據時最後一列是組合框的類型。
DataGridView1.DataSource = myDataSet
在此先感謝。
我的價值是什麼? – WozzeC
對不起,我沒有看到。我= Datagridview1.CurrentRow.Index,感謝您指出。 –