DataGridViewComboBoxCell comboBoxCell = uiDataGridView1.Rows[uiDataGridView1.Rows.Count - 1].Cells[1] as DataGridViewComboBoxCell;
comboBoxCell.DisplayMember = "123";
comboBoxCell.ValueMember = "0";
comboBoxCell.DataSource = list;
如果C# DataGridViewComboBoxCell一直为空,可能是以下原因之一:
数据绑定问题:请确保您已正确将数据绑定到DataGridView控件。检查您的数据源是否具有所需的数据,以及是否正确设置了DataGridView的DataSource属性。
单元格类型不正确:在DataGridView中,您可能将单元格类型设置为DataGridViewTextBoxCell而不是DataGridViewComboBoxCell。请确保在创建DataGridView时,已将单元格类型设置为DataGridViewComboBoxCell。
缺少数据:请检查您的数据源是否包含所需的数据。如果数据源中没有数据,则DataGridViewComboBoxCell将显示为空。
缺少下拉箭头:DataGridViewComboBoxCell需要一个下拉箭头来显示选项。请确保已启用下拉箭头。您可以通过设置DataGridView的SortMode属性为DataGridViewColumnSortMode.Automatic来启用下拉箭头。
缺少选项:请检查您的DataGridViewComboBoxCell是否包含任何选项。如果没有选项可供选择,则该单元格将显示为空。您可以通过设置DataGridViewComboBoxCell的Items属性来添加选项。
如果以上步骤都没有解决问题,请尝试调试代码以查找其他问题。