Hello :) I have an object, Car
which contains an object, Engine
as one of its members. I have a collection of Car
objects and I want to bind a drop down list to the collection, displaying a property of the contained Engine
object:
class Car
{
public Engine engine; // contains the engine object
public string manufacturer;
}
class Engine
{
public int capacity;
}
In my code I create a Cars collection: Cars cars = new Cars(); I add my car objects to the collection and bind my collection to a drop doown list:
myDropDownList.DataSource = cars;
myDropDownList.DataValueField = "engine.capacity";
myDropDownList.DataTextField = "engine.capacity";
myDropDownList.DataBind();
This doesn't work though because the fields won't accept the syntax I use to specify the contained object's member. On the other hand, this works fine:
myDropDownList.DataSource = cars;
myDropDownList.DataValueField = "manufacturer";
myDropDownList.DataTextField = "manufacturer";
myDropDownList.DataBind();
Can anyone tell me how to get my drop down list to bind so that I can display the contained object's member? Thanks :)