[英]Winforms bind to a combobox in a datagridview
我有一个DataGridView,绑定了BindingSource,以显示对象的集合。 我可以轻松地将TextboxColumn的数据绑定到DataGridView以显示数据源中的数据。
但是,数据源的属性之一是选择对象。 我尝试将ComboboxColumn与网格进行数据绑定,但是在显示choice属性的文本时并不高兴。
我有以下内容:
// 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";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.