c# add a dgv row with a dataGridViewComboBoxCell

前端 未结 3 1520
礼貌的吻别
礼貌的吻别 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:23

    If you need to keep configured columns try something like this:

    dataGridView1.Rows.Add();
    DataGridViewRow tmp = dataGridView1.Rows[dgvMatw.Rows.Count - 1];
    tmp.Cells[0] = true;
    tmp.Cells[1] = "str1";
    tmp.Cells[2] = "str2";
    ((DataGridViewComboBoxCell)tmp.Cells[3]).Value = 1;
    ((DataGridViewComboBoxCell)tmp.Cells[4]).Value = 2;
    

    Values 1 and 2 where example only. It must be type of your DataGridViewComboBoxColumn.ValueMember. I was searching for this topic, so I thought someone could use it.

提交回复
热议问题