Existing column with Combobox in datagridview in vb.net

I am trying to put a drop on an existing DataGridView column. I am filling the grid from excel source and into the specific column that I need.

`

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)

      

`


In this code, I added another column to the table. But I want to fall out on an existing column.

+3


source to share


2 answers


First you need to delete this old column, after which you need to fill data from excel into a new column



0


source


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 bind your comboBox that is populated before you bind it to the cell. Your column name should be "Comments", not just the header text. You get the 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

      

0


source







All Articles