Click here to Skip to main content
15,914,413 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I have a datagridview combo box column with Read Only property set to False.
I need to insert values to the combo box (say One, Two, Three etc.) and also I need the combo box to display a certian value stored in a variable (say dim abc as string="value")

I need the combo box to display value stored in abc when the form loads.

Please advise how to achieve these two tasks.

Thanks
Posted
Comments
Maciej Los 29-Nov-13 6:39am    
Have you seen it: DataGridViewComboBoxCell Class[^]?

1 solution

Hi try this

VB
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Call LoadDataInComboBox()

    Dim int As Int32 = Me.DataGridView1.Rows.Add()
    Dim FirstRow As DataGridViewRow = Me.DataGridView1.Rows(int)

    FirstRow.Cells(Column1.Index).Value = "Two"
End Sub


Sub LoadDataInComboBox()
    Dim cboColumn As DataGridViewComboBoxColumn = Me.DataGridView1.Columns(Column1.Index)


    cboColumn.Items.Add("One")
    cboColumn.Items.Add("Two")
    cboColumn.Items.Add("Three")

    'or you can load any array or collection

    Dim values As String() = New String() {"One", "Two", "Three"}
    cboColumn.DataSource = values
    'you can specify the display and value memer
    'cboColumn.ValueMember = "IdField"
    'cboColumn.DisplayMember = "DisplayField"



End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900