您的位置:程序门 -> .net技术 -> c#



combobox怎么绑定选项和真实值?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


combobox怎么绑定选项和真实值?
发表于:2007-02-27 14:37:52 楼主
我有个combobox,假如里面有个“22秒”的选项,我在程序里使用的是“22秒”对应的“22”,我应该怎么做?(不是数据库绑定)
发表于:2007-02-27 16:46:571楼 得分:0
using   system;
using   system.collections   ;

namespace   xzm.backdeal
{
public   class   userinttype
{
private   string   _display   ;
private   int   _val;

public   userinttype(string   display   ,   int   val)
{
this._display   =   display;
this._val   =   val;
}

public   string   displayname
{
get{return   this._display;}
}

public   int   valuename
{
get{return   this._val;}
}
}
}
在初始化combobox时
定义一个arraylist
给arraylist添加userinttype实例
设置combobox的datasource为arraylist就可以啦
发表于:2007-02-27 16:48:312楼 得分:0
调用代码
private   void   initflagcombobox()
{
arraylist   types   =   new   arraylist();
types.add(new   xzm.backdeal.userinttype( "销售客户 ",0   ));
types.add(new   xzm.backdeal.userinttype( "生产客户 ",1   ));

this.cmb_flag.datasource   =   types;
this.cmb_flag.displaymember   =   "displayname ";
this.cmb_flag.valuemember   =   "valuename ";
this.cmb_flag.text   =   " ";
}
发表于:2007-02-28 11:33:353楼 得分:0
我有点没明白,
private   void   initflagcombobox()
{
arraylist   types   =   new   arraylist();
types.add(new   xzm.backdeal.userinttype( "销售客户 ",0   ));
types.add(new   xzm.backdeal.userinttype( "生产客户 ",1   ));

this.cmb_flag.datasource   =   types;
this.cmb_flag.displaymember   =   "displayname ";
this.cmb_flag.valuemember   =   "valuename ";
this.cmb_flag.text   =   " ";
}
怎么做我的下拉标签是 "销售客户 ", "生产客户 ",那隐藏的项目数值是那个0,1吗?怎么得到这个项目数值是cmb_flag.valuemember?
发表于:2007-02-28 12:16:264楼 得分:0
我弄明白了!
谢谢   to   heshl()
发表于:2007-02-28 12:36:585楼 得分:0
还有个问题每个combobox都要这样做吗?假如我有9个combobox的标签内容和项目数值都一样.我都要这样做一次吗?
                    arraylist   types   =   new   arraylist();
                        types.add(new   wulin.userinttype( "0键 ",   48));
                        types.add(new   wulin.userinttype( "1键 ",   49));
                        types.add(new   wulin.userinttype( "2键 ",   50));
                        types.add(new   wulin.userinttype( "3键 ",   51));
                        types.add(new   wulin.userinttype( "4键 ",   52));
                        types.add(new   wulin.userinttype( "5键 ",   53));
                        types.add(new   wulin.userinttype( "6键 ",   54));
                        types.add(new   wulin.userinttype( "7键 ",   55));
                        types.add(new   wulin.userinttype( "8键 ",   56));
                        types.add(new   wulin.userinttype( "9键 ",   57));
                        types.add(new   wulin.userinttype( "f1键 ",   112));
                        types.add(new   wulin.userinttype( "f2键 ",   113));
                        types.add(new   wulin.userinttype( "f3键 ",   114));
                        types.add(new   wulin.userinttype( "f4键 ",   115));
                        types.add(new   wulin.userinttype( "f5键 ",   116));
                        types.add(new   wulin.userinttype( "f6键 ",   117));
                        types.add(new   wulin.userinttype( "f7键 ",   118));
                        types.add(new   wulin.userinttype( "f8键 ",   119));
                        types.add(new   wulin.userinttype( "f9键 ",   120));
                        types.add(new   wulin.userinttype( "f10键 ",   121));
                        types.add(new   wulin.userinttype( "f11键 ",   122));
                        types.add(new   wulin.userinttype( "f12键 ",   123));
发表于:2007-02-28 14:19:486楼 得分:0
是,不过,你可以自己编段方法,把加载过程写的简单好看些,呵呵


快速检索

最新资讯
热门点击