existing column with Combobox in datagridview in vb.net

1.9k views Asked by At

I am trying to put a drop down on the existing column of the DataGridView. I am filling the grid from excel source and to a specific column i need drop down.

`

Dim comboBoxColumn As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
DataGridView1.DataSource = dataSetOld.Tables("Old")
comboBoxColumn.HeaderText = "Comments"
comboBoxColumn.Items.Add("Resolution Breach")
comboBoxColumn.Items.Add("Response Breach")
DataGridView1.Columns("Comments").DataGridView.Columns.Add(comboBoxColumn)

`


By this code I have added another column to the grid. But i want a drop down onto the existing column.

2

There are 2 answers

0
Panchal jigar On

First u have to remove that old column and after that u have to fill data from excel into new column

4
Mirko Tipka On
Dim gridComboBox As New DataGridViewComboBoxCell
     gridComboBox.Items.Add("Resolution Breach")       'Populate the Combobox
     gridComboBox.Items.Add("Response Breach")         'Populate the Combobox
DataGridView1.Item(combobox_column, combobox_row) = gridComboBox

For each cell in your column, you need to link your comboBox, that is populated before linking it to cell. Name of your Column has to be "Comments" and not just header text. You get column name from your source (database). ..in your case:

Dim comboBoxColumn As DataGridViewComboBoxColumn = New DataGridViewComboBoxColumn()
Dim combobox_row as Integer

    DataGridView1.DataSource = dataSetOld.Tables("Old")
    comboBoxColumn.HeaderText = "Comments"
    comboBoxColumn.Items.Add("Resolution Breach")
    comboBoxColumn.Items.Add("Response Breach")
    for combobox_row = 0 to DataGridView1.RowCount - 1
        DataGridView1.Item("Comments", combobox_row) = comboBoxColumn
    next combobox_row