简体   繁体   中英

Binding Devexpress controls to nested property

These question asked me by a friend and i can't solve it too. Sample code using EF6 and devexpress winform components.

I'm creating LookupEditControl with 2 columns.

       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;

Look at last 3 lines of code. Column bounded to "Country.Name" is always empty. But other one works.

How can i bound LookupEditControls column to Nested Property of a business object?

Accordingly to the following DevExpress Support ticket there is no support of nested properties in LookupEdit.
But I believe you can use the GridLookupEdit instead:

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" } },
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM