日期:2014-05-18  浏览次数:20916 次

关于winform combobox的问题(本人新手)
最近刚刚从ASP转过来研究.net(c#),先搞一个简单的东东看看,遇到以下问题:
combobox相关代码

//定义一个类
public class Dropselect
  {
  public Dropselect(int id, string skey, string title)
  {
  this.Id=id;
  this.Skey=skey;
  this.Title=title;
  }
  public int Id;
  public string Skey;
  public string Title;
  }

//将选项添加进去
this.comboBox5.Items.AddRange(new object[] {
  new Dropselect(0,"xx","-条件1-"),
  new Dropselect(1,"FBillNo","订单号"),
  new Dropselect(2,"FDeptId","部 门"),
  new Dropselect(3,"FEmpId","业务员"),
  new Dropselect(4,"FModel","型 号"),
  new Dropselect(5,"FItemId","品 牌"),
  new Dropselect(6,"FCustId","客 户")});
  this.comboBox5.DisplayMember = "Title";
  this.comboBox5.ValueMember = "Skey";

VS没有报错,可运行出来显示的是"WindowsFormsApplication1.MainFrame.Dropselect"
不知道怎么回事?

------解决方案--------------------
办法1:
public class Dropselect
{
public override string ToString()
{
return Title;
}
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id;
public string Skey;
public string Title;
}
办法二
public class Dropselect
{
public Dropselect(int id, string skey, string title)
{
this.Id=id;
this.Skey=skey;
this.Title=title;
}
public int Id { get; set; }
public string Skey { get; set; }
public string Title { get; set; }
}