【发布时间】:2014-01-31 05:51:09
【问题描述】:
我在为 DataGridViewComboBoxColumn 的 DataPropertyName 设置正确的数据属性时遇到问题。我有一个 BindingSource 并将其 DataSource 设置为自定义对象的 BindingList。这些对象具有我想分配为 DataGridView (pluginsDataGrid) 中的列的属性:
var source = new BindingSource {DataSource = _plugins};
pluginsDataGrid.AutoGenerateColumns = false;
pluginsDataGrid.DataSource = source;
当我有一个简单的字符串作为属性时,一切都很好 - 它是名称:
using (var nameCol = new DataGridViewTextBoxColumn())
{
nameCol.DataPropertyName = "Name";
nameCol.Name = "Name";
pluginsDataGrid.Columns.Add(nameCol);
}
但我不知道如何设置 DataGridViewComboBoxColumn 选项。我用这种方式试了一下:
using (var depCol = new DataGridViewComboBoxColumn())
{
depCol.DataPropertyName = "Dependencies";
depCol.Name = "Dependencies";
pluginsDataGrid.Columns.Add(depCol);
}
其中 Dependencies 是字符串列表。但它不起作用。应该给它分配什么样的属性?
【问题讨论】: