我正在使用以下代码从业务对象列表中填充一个组合框:
Dim manufacturers As IList(Of ElectronicsManufacturer) = _electronicLogic.GetManufacturers(category.CategoryID)
If (manufacturers.Count > 0) Then
Me.cbxManufacturer.Enabled = True
Me.cbxManufacturer.Items.Add("(Please Select...)")
Me.cbxManufacturer.Items.Add(manufacturers.ToArray())
我遇到的问题是组合框不显示字符串,而是显示业务对象名称。
我像往常一样在业务对象中设置了覆盖:
public class ElectronicsManufacturer
{
public ElectronicsManufacturer()
{
ManufacturerID = -1;
ManufacturerName = string.Empty;
RequireSerialNumber = false;
}
public int ManufacturerID { get; set; }
public string ManufacturerName { get; set; }
public bool RequireSerialNumber { get; set; }
public override string ToString()
{
return ManufacturerName.ToString();
}
}
但是组合框只显示 ElectronicsManufacturer[] Array
我可以确认manufacturers
在填充组合框时包含 52 个项目。