文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>[转]c#(winform) 中 ComboBox ListBox 添加项完全解决

[转]c#(winform) 中 ComboBox ListBox 添加项完全解决

时间:2010-11-17  来源:小さいです哥

首先添加类ListItem:
 /// <summary>
 /// 选择项类,用于ComboBox或者ListBox添加项
 /// </summary>
 public class ListItem
 {
  private string id = string.Empty;
  private string name = string.Empty;
  public ListItem(string sid, string sname)
  {
   id = sid;
   name = sname;
  }
  public override string ToString()  
  {  
   return this.name;
  }
  public string ID
  {
   get
   {
    return this.id;
   }
   set
   {
    this.id = value;
   }
  }
  public string Name
  {
   get
   {
    return this.name;
   }
   set
   {
    this.name = value;
   }
  }
 }

然后在程序中使用:
ListItem item = new ListItem("我是值", "我是名字");
this.lbChoiceRoom.Items.Add(item);
this.lbChoiceRoom.DisplayMember = "Name";
this.lbChoiceRoom.ValueMember = "ID";

排行榜 更多 +
梦幻甜心蛋糕店手游 v1.0 安卓版

梦幻甜心蛋糕店手游 v1.0 安卓版

休闲益智 下载
狙击手血战鬼子 v8081.23.10.7 安卓版

狙击手血战鬼子 v8081.23.10.7 安卓版

休闲益智 下载
狙击手血战鬼子 v8081.23.10.7 安卓版

狙击手血战鬼子 v8081.23.10.7 安卓版

休闲益智 下载