winforms DataGridViewComboBoxColumn,当​​设置DataPropertyName时,ComboBox无法单击

时间:2016-05-16 12:31:48

标签: c# winforms datagridview datagridviewcombobox

我有带有数据源绑定的DataGridViewComboBoxColumn的DataGridView,当我绑定DataGridView的DataPropertyName时, ComboBox变得无法点击。

bool operator()(unsigned x, unsigned y, unsigned z) const { 
     return _data[_zSize*_ySize*x + y*_zSize + z]; 
}

正确的DataPropertyName与每行绑定,但我无法从下拉列表中选择

dgFMS.ReadOnly = false;

我也在实施dgFMS_EditingControlShowing

BindingSource _bsCats2 = new BindingSource();
DataGridViewComboBoxColumn catCol = new DataGridViewComboBoxColumn();
_bsCats2.DataSource = CategoryManager.Categories.Select(x => new { 
    Key = x.ParentWithName.ToLowerInvariant(), 
    Value = x.Id })
    .ToList();
catCol.DataSource = _bsCats2;
catCol.DataPropertyName = "catID";
catCol.DisplayMember = "Key";
catCol.ValueMember = "Value";
catCol.Width = 250;
catCol.ReadOnly = false;
dgFMS.Columns.Add(catCol);
dgFMS.ReadOnly = false;

1 个答案:

答案 0 :(得分:0)

我发现了绑定数据的问题

DataPropertyName =" catID"是只读属性,只有没有像这样的setter的getter

public int catID
    {
        get
        {
            return CategoryManager.Categories.FirstOrDefault(x => x.Name.Equals(SubCategory, StringComparison.InvariantCultureIgnoreCase)).Id;
        }
    }  

通过添加属性的setter解决了问题。