【问题标题】:get a specific item in DataGridViewComboBoxCell c#在 DataGridViewComboBoxCell c# 中获取特定项目
【发布时间】:2015-02-12 09:00:16
【问题描述】:

我的 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];

【问题讨论】:

    标签: c#


    【解决方案1】:

    我给你点击特定单元格的代码。

    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()
            }
        }
    

    【讨论】:

      【解决方案2】:

      这是我编码的答案:

      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;
      

      【讨论】:

        猜你喜欢
        • 2015-07-20
        • 1970-01-01
        • 1970-01-01
        • 2013-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-12
        • 1970-01-01
        相关资源
        最近更新 更多