c# add a dgv row with a dataGridViewComboBoxCell

前端 未结 3 1491
礼貌的吻别
礼貌的吻别 2021-01-27 00:34

I\'m currently trying to add a ComboBox to a dataGridView.

In the DGV, there are 5 columns: checkbox, string, string, combobox, combobox.

both combobox-columns a

3条回答
  •  滥情空心
    2021-01-27 01:34

    I'm not entirely clear what you're trying to do here, but if you're just trying to choose a value from the combobox for each row you add, you can choose an existing combobox value as a string.

    If I have a two column datagridview, both with comboboxes that are pre-populated (I populated my comboboxes in the datagridview control itself by simply editing each column and adding my choices to the collection there), then I can do this:

    Public Class Form1
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            Dim newRow(1) As Object
            newRow(0) = "Foo"
            newRow(1) = "Bar"
            DataGridView1.Rows.Add(newRow)
        End Sub
    End Class
    

    So "Foo" and "Bar" are already choices in the comboboxes. I can populate each row by simply referring to the choice I want by name. I would guess I could also do this by index number if I wanted to.

    Hope this helps!

提交回复
热议问题