1

我有一个具有不同列的 dataGridView。其中之一是具有默认选择(英语、德语、中文...)的 ComboBoxColumn。我以编程方式将新行添加到我的数据网格视图中。

dataGridView1.Rows.Add(sn, givenName, mail, department, ToDo);

第五列是我的 ComboBoxColumn,目前写着“ToDo”。我想说应该选择我的哪个comboBoxItems。例如像这样:

dataGridView1.Rows.Add(sn, givenName, mail, department, 1);

现在应该在我的组合框中选择德语。我在 Form1.designer.cs 中设置了 Items。

稍后我想获得为每一行选择的项目的值。

4

2 回答 2

0

你应该可以说:

// Assuming your combo box column is named 'comboBoxColumn1'
dataGridView1.Rows.Add(sn, givenName, mail, department, comboBoxColumn1.Items[1]);

有关设置_Items

于 2011-11-17T11:30:57.433 回答
0
foreach (DataGridViewRow row in dataGridView1.Rows)
{
      DataGridViewComboBoxCell cell = row.Cells[0] as DataGridViewComboBoxCell;
}

现在您可以从单元格变量中访问您的值。

编辑: Cells[] 中的 0 号当然不适合您的示例。

于 2011-11-17T11:35:09.910 回答