【发布时间】:2017-11-17 00:32:11
【问题描述】:
我应该补充一点,对象是在第 3 方.dll 中管理的,所以我的代码中实际上没有对象定义。
我有一个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
}
正如我的实现 cmets 中列出的那样,我想在打开下拉列表时显示 Foo.Settings.Title,但稍后选择它时仍然需要完整的对象。
【问题讨论】:
-
这是winforms吗? WPF? UWP? ASP.NET?
-
糟糕,它是 winforms。
标签: c# winforms drop-down-menu combobox