C# Winforms绑定到datagridview中的组合框
我有一个绑定了BindingSource的DataGridView,用于显示对象的集合。我可以轻松地将TextboxColumn数据绑定到DataGridView,以显示数据源中的数据 但是,数据源的属性之一是choice对象。我曾尝试将ComboboxColumn与网格进行数据绑定,但在显示choice属性的文本时没有任何乐趣 我有以下资料:C# Winforms绑定到datagridview中的组合框,c#,winforms,data-binding,datagridview,combobox,C#,Winforms,Data Binding,Datagridview,Combobox,我有一个绑定了BindingSource的DataGridView,用于显示对象的集合。我可以轻松地将TextboxColumn数据绑定到DataGridView,以显示数据源中的数据 但是,数据源的属性之一是choice对象。我曾尝试将ComboboxColumn与网格进行数据绑定,但在显示choice属性的文本时没有任何乐趣 我有以下资料: // bind to the datagrid this.datagridBindingSource.DataSource = collectionFo
// bind to the datagrid
this.datagridBindingSource.DataSource = collectionForDatagrid;
this.dataGrid.DataSource = this.datagridBindingSource.DataSource;
// now bind the collection of choices to the combobox column
this.choiceDataGridViewComboBoxColumn.DataSource = choiceCollection;
// set the display and value members of the combobox
this.choiceDataGridViewComboBoxColumn.DisplayMember = "Name";
this.choiceDataGridViewComboBoxColumn.ValueMember = "ID";
但是组合框中似乎没有显示任何内容。“DisplayMember”和“ValueMember”是“choiceCollection”中对象的属性
有什么想法吗?啊,新手错了!我忘了下面这句话:
this.choiceDataGridViewComboBoxColumn.DataPropertyName = "ID";
您希望绑定到所选数据源的数据源中的
属性是什么?您和我同时注意到了这个问题!。。。事实上,我没有设置“DataPropertyName”属性。就在我按下“post”的那一秒,我想到答案的次数!