且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将项目添加到DataGridView中的组合框

更新时间:2023-11-28 17:51:34

您可以尝试通过网格的 DataBindingComplete 添加它们

You may try to add them via DataBindingComplete of the grid

这些东西上的东西

void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
       if (row.Cells[0] is DataGridViewComboBoxCell && row.Index == 1)
          (row.Cells[0] as DataGridViewComboBoxCell).Items.Add("A");
       else
          (row.Cells[0] as DataGridViewComboBoxCell).Items.Add("B");
    }
}

希望这会有所帮助编辑

(row.Cells[0] as DataGridViewComboBoxCell).Value = (row.Cells[0] as DataGridViewComboBoxCell).Items[0];

选中该单元格后,第一个值将显示为选中状态

When that cell is selected then the first value would be shown selected