【发布时间】:2013-08-10 10:02:13
【问题描述】:
我有一个绑定了 BindingSource 的 DataGridView,用于显示对象集合。我可以轻松地将 TextboxColumn 数据绑定到 DataGridView 以显示来自数据源的数据。
但是,数据源的属性之一是选择对象。我尝试将 ComboboxColumn 与网格进行数据绑定,但在显示选择属性的文本时没有任何乐趣。
我有以下几点:
// 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”中对象的属性。
有什么想法吗?
【问题讨论】:
-
你想绑定到
choiceDataGridViewComboBoxColumn的数据源中的Property是什么? -
您和我同时注意到了这个问题!...我实际上并没有设置“DataPropertyName”属性。按下“post”的那一秒,我想到答案的次数!
标签: c# winforms data-binding datagridview combobox