文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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";

排行榜 更多 +
建筑模拟器最新版

建筑模拟器最新版

模拟经营 下载
外星战士幸存者手机版

外星战士幸存者手机版

飞行射击 下载
萌宠模拟器手机版

萌宠模拟器手机版

休闲益智 下载