我應該補充說,這些對象是在第三方管理的.dll
,所以我實際上沒有在我的代碼中的對象定義。如何將組合框的Display成員設置爲嵌套在對象列表中的字符串?
我有一個List<Foo>
,我將其設置爲ComboBox
的數據源。
假設Foo
物體看起來像:這裏
public class Foo
{
Settings setting;
public Foo(string title)
{
setting = new Settings();
setting.Title = title;
}
//lots of other objects and values
}
public class Settings
{
public Settings()
{
}
public String Title {get; set;}
//lot of other information
}
,我的實:
private void LoadList() //edited for SO testing sake, this is called in constructor
//of the form
{
var foo = new List<Foo> {
new Foo("MASTER 5DAY"),
new Foo("5 Day Reminder"),
new Foo("MASTER Welcome"),
new Foo("Welcome Letter")
};
var master = foo.Where(x => x.Settings.Title.Contains("MASTER")).ToList();
this.ddlMasterType = master; //This is the combobox
//Now here I would want the display member of the ddl to be the title of each Foo object
//But I need the value member to still contain all the other information of the Foo object
}
正如我在實施意見中列出,我想顯示Foo.Settings。標題,當我打開下拉列表,但我仍然需要完整的對象,當我稍後選擇它。
這是winforms嗎? WPF? UWP? ASP.NET? –
Woops我不好,它是winforms。 – Adam