【发布时间】:2009-08-30 17:19:43
【问题描述】:
嗯,我的问题有点傻,但我尝试了很多不同的东西,但没有结果。
我的主窗体中有一个 ComboBox,我想将其数据源指向在 Filters 类中声明的公共只读 List PriceChanges 列表。没问题,但我想列出描述字段。
我尝试将“描述”字符串分配给 DisplayMember 属性,但没有成功。我的 ComboBox 仅列出:每个条目的“BusinessLogic.PriceChange”,其中 BusinessLogic 是我的命名空间的名称,PriceChange 是类。
感谢您的帮助。
问候
这是我的主窗体代码的一部分
public mainFrm()
{
InitializeComponent();
prodFilter = new Filters();
cbPriceChanges.DataSource = prodFilter.PriceChanges;
cbPriceChanges.DisplayMember = "Description"
}
这是声明 List 对象的代码的一部分
public enum PriceChangeTypes
{
No_Change,
Increased,
Decreased,
All
}
public class PriceChange
{
public String Description;
public readonly PriceChangeTypes Type;
public delegate bool ComparisonFuntionDelegate(Decimal a);
public readonly ComparisonFuntionDelegate ComparisonFunction;
public PriceChange(String Description, PriceChangeTypes type , ComparisonFuntionDelegate CompFunc)
{
this.Description = Description;
Type = type;
ComparisonFunction = CompFunc;
}
}
public class Filters
{
public readonly List<PriceChange> PriceChanges = null;
public Filters()
{
PriceChanges = new List<PriceChange>();
PriceChanges.Add(new PriceChange("No Change", PriceChangeTypes.No_Change, PriceChange => PriceChange == 0));
PriceChanges.Add(new PriceChange("Increased", PriceChangeTypes.Increased, PriceChange => PriceChange > 0));
PriceChanges.Add(new PriceChange("Decreased", PriceChangeTypes.Decreased, PriceChange => PriceChange < 0));
PriceChanges.Add(new PriceChange("All", PriceChangeTypes.All, a => true));
}
}
【问题讨论】:
-
Description、Type、ComparisonFuntionDelegate 和 ComparisonFunction 应该是私有的或者做成属性。
标签: c# user-interface list combobox