这个问题由朋友问我,我也无法解决。使用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列绑定到业务对象的嵌套属性?
答案 0 :(得分:1)
相对于following DevExpress Support ticket,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" } },
};