C# BindingSource与DataGridView组合框

C# BindingSource与DataGridView组合框,c#,winforms,C#,Winforms,我知道可以将BindingSource对象与DataGridView一起使用 有没有可能在其中一列中有一个组合框,但仍然可以利用BindingSource?是的,它是-查看: 将ComboBox与DataGridView结合使用不再那么复杂,但在进行一些数据驱动的软件开发时,它几乎是强制性的 我已经创建了一个像这样的DataGridView。现在,我想在DataGridView中显示“月”和“项”,而不是“月”和“项ID” 本质上,本文描述的是将组合框与单独的绑定源绑定—在本例中,是一个验证表

我知道可以将
BindingSource
对象与DataGridView一起使用


有没有可能在其中一列中有一个组合框,但仍然可以利用
BindingSource

是的,它是-查看:

将ComboBox与DataGridView结合使用不再那么复杂,但在进行一些数据驱动的软件开发时,它几乎是强制性的

我已经创建了一个像这样的DataGridView。现在,我想在DataGridView中显示“月”和“项”,而不是“月”和“项ID”

本质上,本文描述的是将组合框与单独的绑定源绑定—在本例中,是一个验证表,其中存储了
MonthID
MonthName
,并根据原始数据的id显示月份名称

在这里,他设置了月份数据源,从月份表中进行选择,然后从返回的数据中创建一个
BindingSource

//Month Data Source
string selectQueryStringMonth = "SELECT MonthID,MonthText FROM Table_Month";
SqlDataAdapter sqlDataAdapterMonth = new SqlDataAdapter(selectQueryStringMonth, sqlConnection);
SqlCommandBuilder sqlCommandBuilderMonth = new SqlCommandBuilder(sqlDataAdapterMonth);
DataTable dataTableMonth= new DataTable();
sqlDataAdapterMonth.Fill(dataTableMonth);
BindingSource bindingSourceMonth = new BindingSource();
bindingSourceMonth.DataSource = dataTableMonth;
然后,他将month ComboBoxColumn添加到DataGridView中,使用上面创建的
DataSource
作为
BindingSource

//Adding  Month Combo
DataGridViewComboBoxColumn ColumnMonth = new DataGridViewComboBoxColumn();
ColumnMonth.DataPropertyName = "MonthID";
ColumnMonth.HeaderText = "Month";
ColumnMonth.Width = 120;
ColumnMonth.DataSource = bindingSourceMonth;
ColumnMonth.ValueMember = "MonthID";
ColumnMonth.DisplayMember = "MonthText";
dataGridViewComboTrial.Columns.Add(ColumnMonth);
最后,他将
DataGridView
绑定到原始数据