0

私は ComboBoxCell を持つ datagridview を持っています,,, 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 に答える