Nim Nagpal
Nim Nagpal

Reputation: 49

existing column with Combobox in datagridview in vb.net

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.

Upvotes: 3

Views: 1943

Answers (2)

Mirko Tipka
Mirko Tipka

Reputation: 11

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

Upvotes: 0

Panchal jigar
Panchal jigar

Reputation: 1

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

Upvotes: 0

Related Questions