Search code examples
vb.netdatagridviewcomboboxtextboxcell

vb.net change datagridview column type to combobox


can I change textbox column in datagridview in vb.net to combobox column type at run time? I know that can be done in design time but I want to do that programatically.


Solution

  • If you are in runtime you will have to remove the column and then add a combobox column. Make sure that the Items list of your combobox contains the data value or an exception will be thrown.

    With DataGridView1
        If .Rows.Count = 0 Then Exit Sub
        i = Datagridview1.currentrow.index
    
        Dim gridComboBox As New DataGridViewComboBoxCell
        gridComboBox.Items.Add("A") 'Populate the Combobox
        gridComboBox.Items.Add("B") 'Populate the Combobox
        gridComboBox.Items.Add("C") 'Populate the Combobox
        .Item(8, i) = gridComboBox
    End With