2015-02-12 61 views
0

我在DataGridViewComboBoxCell中有一些项目,当窗体加载时我需要在该DataGridViewComboBoxCell中显示特定项目。在DataGridViewComboBoxCell中获取特定项目#

这里是代码 -

DataGridViewComboBoxCell cbc = new DataGridViewComboBoxCell(); 

foreach (String item in objectListBoxList[listboxNumber].GetItemInList()) 
{ 
    cbc.Items.Add(item); 
} 
dataGridViewList[tableNumber].Rows[parameter.getRow()].Cells[1] = cbc; 

我需要它是这样的---

dataGridViewList[tableNumber].Rows[parameter.getRow()].Cells[1] = cbc.Items[1]; 

回答

0

我给你点击特定小区的代码。

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) 
{ 
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) 
    { 
      // Show in messagebox 
      MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()); 
      // Set the value to string 
      String value = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString() 
     } 
    } 
0

这是我编写了答案:

DataGridViewComboBoxCell cbc = new DataGridViewComboBoxCell(); 
foreach (String item in objectListBoxList[listboxNumber].GetItemInList()) 
{ 
    cbc.Items.Add(item); 
} 
// this line sets the default item in DataGridViewComboBoxCell to be at index 0-- 
cbc.Value = myListBox[0];  
dataGridViewList[tableNumber].Rows[parameter.getRow()].Cells[1] = cbc;