1

这些问题是朋友问我的,我也解决不了。使用 EF6 和 devexpress winform 组件的示例代码。

我正在使用 2 列创建 LookupEditControl。

       var cities = context.Cities.Include(p=>p.Country)
            .OrderBy(e => e.City.Name)
            .OrderBy(e=>e.CountryISOCode)
            .ToList();

        //countryLookUpEdit.Properties.DataSource = cities;

        countryLookUpEdit.Properties.DisplayMember = "Name";
        countryLookUpEdit.Properties.ValueMember = "ID";           

        countryLookUpEdit.Properties.Columns.Clear();

        // this column always empty, but Console.WriteLine dumps it
        countryLookUpEdit.Properties.Columns.Add(new LookUpColumnInfo("Country.Name", "Country Name", 225));

        // this column works
        countryLookUpEdit.Properties.Columns.Add(new LookUpColumnInfo("Name", "City Name", 150));

        countryLookUpEdit.Properties.DataSource = cities;

查看最后 3 行代码。绑定到“Country.Name”的列始终为空。但另一个有效。

如何将 LookupEditControls 列绑定到业务对象的嵌套属性?

4

1 回答 1

1

根据以下 DevExpress Support 票证,在 LookupEdit 中不支持嵌套属性。
但我相信您可以改用GridLookupEdit

gridLookUpEdit.Properties.DisplayMember = "Name";
gridLookUpEditView.Columns.Add(
    new GridColumn() { FieldName = "Name", Visible = true });
gridLookUpEditView.Columns.Add(
    new GridColumn() { FieldName = "Country.Name", Caption = "Country", Visible = true });
gridLookUpEdit.Properties.DataSource = new List<City> { 
    new City() { Name="New York", Country = new Country() { Name = "USA" } },
    new City() { Name="London", Country = new Country() { Name = "UK" } },
};
于 2013-11-08T06:31:51.967 回答