Reputation: 115
I have this code which i am using to populate a combo box in a datagridview
Dim dgvcc As DataGridViewComboBoxCell
dgvcc = DataGridView2.Rows(0).Cells(2)
dgvcc.Items.Add("comboitem1")
dgvcc.Items.Add("comboitem2")
it works fine but when a new row is added to the datagridview
the combo box is not popuated with the data - i want it to be populated with the same data for every row
Upvotes: 0
Views: 3910
Reputation: 6608
Instead of assigning the selections to an individual DataGridViewComboBoxCell
(which would be only for that specific cell), assign the selections to the entire DataGridViewComboBoxColumn
instead. Doing this will mean every cell in the column will share the same selection options.
With DirectCast(DataGridView2.Columns(2), DataGridViewComboBoxColumn)
.Items.Add("comboitem1")
.Items.Add("comboitem2")
End With
Note that I am assuming column 2
is your combo box column since that is what is used in your snippet.
Upvotes: 1