2011-11-17 49 views
1

我有一個dataGridView具有不同的列。其中之一是具有默認選項(英語,德語,中文...)的ComboBoxColumn。我以編程方式將新行添加到我的datagridview。從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。

後來我想知道爲每個行選擇Item的值。

回答

0

你應該能夠說:

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

用於設置Items

0
foreach (DataGridViewRow row in dataGridView1.Rows) 
{ 
     DataGridViewComboBoxCell cell = row.Cells[0] as DataGridViewComboBoxCell; 
} 

現在你可以從細胞變量來訪問你值的例子見this MSDN page

編輯: Cells []中Ofcourse number 0不適合你的例子。

相關問題