COMBOBOX怎么绑定选项和真实值?
我有个combobox,假如里面有个“22秒”的选项,我在程序里使用的是“22秒”对应的“22”,我应该怎么做?(不是数据库绑定) --------------------编程问答-------------------- 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就可以啦 --------------------编程问答-------------------- 调用代码
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 = "";
} --------------------编程问答-------------------- 我有点没明白,
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? --------------------编程问答-------------------- 我弄明白了!
谢谢 to heshl() --------------------编程问答-------------------- 还有个问题每个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)); --------------------编程问答-------------------- 是,不过,你可以自己编段方法,把加载过程写的简单好看些,呵呵 --------------------编程问答-------------------- 请问 XZM.BackDeal 和cmb_Flag是什么东西?
补充:.NET技术 , C#