0

我有一个 datagridview,它有一个 ComboBoxCell,,,ComboBox 绑定到数据,,我想将它用作传统 ComboBox,我的意思是我想根据它的值显示它的项目(来自显示成员),,

例如

当我这样做时

Datagridview1.CurrentRow.Cells(4).value = 7 '单元格4是DatagridviewComboBoxCell

它给了我一个错误

"DatagridviewComboBoxCell.value 无效",

但我希望这个组合框应该选择并显示值为 7 的项目

我尝试了许多不同的技术,,,但徒劳无功

谢谢,,

4

1 回答 1

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

编辑

我还发现了这个有用的链接

于 2014-11-19T08:42:12.460 回答