简体   繁体   中英

Datagridview box combo box

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

Combobox-type DataGridView cells/columns are, by default, read-only (users cannot change their items). Sample code to start a DataGridView1 with a combobox-type column, populated with the values you wish:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    Dim curCol As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn

    Dim abc As String = "value"
    Dim items As List(Of String) = New List(Of String)()
    items.Add("One")
    items.Add("Two")
    items.Add("Three")
    items.Add(abc)

    curCol.DataSource = items

    DataGridView1.Columns.Add(curCol)

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM