我有两个表:列和表(外键 - Table_ID)。我想用组合框在 dataGridView 中显示列。在组合框中要显示的相关表(名称表)和选定的项目是在列中设置的值。
List<columns> columns = DataLoader.GetColumns();
List<tables> tables = DataLoader.GetTables();
this.editingDataGridView.DataSource = columns; // my dataGridView
DataGridViewComboBoxColumn comboBoxColumn = new DataGridViewComboBoxColumn();
comboBoxColumn.DisplayMember = "Table_Name";
comboBoxColumn.ValueMember = "Table_ID";
comboBoxColumn.DataSource = tables;
//add combobox column in dataGrid
this.editingDataGridView.Columns.Add(comboBoxColumn);
//AND this i want set value
int index = this.editingDataGridView.Columns.IndexOf(comboBoxColumn);
for (int i = 0; i < columns.Count; i++)
{
this.editingDataGridView.Rows[i].Cells[index].Value = columns[i].Table_ID;
}
运行后,我得到带有数据源的组合框列的gridView,但没有选择默认值!