0

I have a datagridview which have a ComboBoxCell,,, ComboBox is bound to data,, I want to use it as Traditional ComboBox,, i mean i want to display its Item (from display members) on the base of its value,,

for example

When i do this

Datagridview1.CurrentRow.Cells(4).value = 7 'Cell 4 is the DatagridviewComboBoxCell

It gives me the error that

"DatagridviewComboBoxCell.value is not valid",

But I want that this combobox should Select And Display the item which value is 7

I have tried manay different techniques,,, but in vain

Thanks,,

skaffman
  • 398,947
  • 96
  • 818
  • 769
Malik
  • 217
  • 2
  • 5
  • 13

1 Answers1

0

Well I know it's kind of late, I hope that I don't wake you. This might help.

    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

EDIT

I Also found this useful link

Community
  • 1
  • 1
Codemunkeee
  • 1,585
  • 5
  • 17
  • 29
  • i tested, because i am searching for an answer. but this doesn't work at all. when answerStr.Rows(x).Item(y).Value is the valuemember – nbk Jan 19 '21 at 15:04