我正在尝试在DataGridView的现有列上放一个下拉列表。我正在从 excel 源填充网格,并填充到我需要下拉的特定列。
'
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)
'
通过此代码,我在网格中添加了另一列。但是我想下拉到现有列上。
首先,您必须删除该旧列,然后必须将数据从excel填充到新列中
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
对于列中的每个单元格,您需要链接在将其链接到单元格之前填充的组合框。列的名称必须是"注释",而不仅仅是标题文本。从源(数据库)获取列名。..在您的情况下:
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