我有一个带有ComboBoxCell的datagridview ,,, ComboBox被绑定到数据,我想用它作为传统的ComboBox,我的意思是我想在它的值的基础上显示它的Item(来自显示成员) ,,
例如
当我这样做时
Datagridview1.CurrentRow.Cells(4).value = 7'Cell 4是DatagridviewComboBoxCell
它给了我错误
“DatagridviewComboBoxCell.value无效”,
但是我希望这个组合框应该选择并显示值为7的项目
我尝试了不同的技术,但是徒劳无功
感谢,,
答案 0 :(得分:0)
嗯,我知道它已经晚了,我希望我不要叫醒你。这可能有所帮助。
For Each question As String In questions
answerStr = 'your query or something that can be used as a datasource, eg datatable'
Dim dgvcc As New DataGridViewComboBoxCell
With dgvcc
.DataSource = answerStr
.ValueMember = "ColumnIDFromAnswerStr"
.DisplayMember = "AnotherColumnFromAnswerStr"
End With
'this is where you can set the combobox
'assuming answerStr is a datatable (not tested code, but i think it will work)
dgvcc.Value = answerStr.Rows(x).Item(y).Value
'assuming you only have one column (combobox)
DataGridView1.Item(0, rowIndex) = dgvcc
rowIndex += 1
dgvcc.Dispose()
Next
我也找到了这个useful link