C#中 combobox 显示数值和实际值怎么绑定
7个回答
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Collections;
namespace ClientDemo
{
public partial class Setting : Office2007Form
{
private int start;
private int process;
private int end;
private int faceQuality;
private int faceConfidence;
private int processIncrement;
private int endIncrement;
private int interval;
private int resolution;
public Setting()
{
搜物 InitializeComponent();
/// <summary>
/// 0=CIF, 1=QCIF, 2=D1 3=UXGA(1600x1200), 4=SVGA(800x600), 5=HD720p(1280x720),6=VGA
/// IPCAM专用{3=UXGA(1600x1200), 4=SVGA(800x600), 5=HD720p(1280x720),6=VGA(640x480) , 7=XVGA, 8=HD900p 桥斗}
/// </summary>
ArrayList al = new ArrayList();
al.Add(new TextAndValue("CIF(352*288)", "0"));
al.Add(new TextAndValue("QCIF(176*144)", "1"));
al.Add(new TextAndValue("4CIF(704*576)", "2"));
al.Add(new TextAndValue("UXGA(1600*1200)", "3"));
al.Add(new TextAndValue("SVGA(800*600)", "4"));
al.Add(new TextAndValue("HD720P(1280*720)", "5"));
al.Add(new TextAndValue("VGA(640*480)", "6"));
al.Add(new TextAndValue("XVGA(1280*960)", "7"));
al.Add(new TextAndValue("HD900P(1600*912)", "8"));
cboResolution.DataSource = al;
cboResolution.DisplayMember = "DisplayText";
cboResolution.ValueMember = "RealValue";
}
private void Setting_Load(object sender, EventArgs e)
{
DBColection.getConfigList();
foreach (DBColection.TraceConfig tc in DBColection.configList)
{
世消液 if (tc.ParamType == "Start") txtMinStartTraceStart.Text = tc.Start.ToString();
else if (tc.ParamType == "Process")
{
txtMinStartTraceProcess.Text = tc.Start.ToString();
nudProcessIncrement.Value = (decimal)tc.Step;
}
else if (tc.ParamType == "End")
{
txtMinStartTraceEnd.Text = tc.Start.ToString();
nudEndIncrement.Value = (decimal)tc.Step;
}
else if (tc.ParamType == "FaceQuality") txtFaceQuality.Text = tc.Start.ToString();
else if (tc.ParamType == "FaceConfidence") txtFaceConfidence.Text = tc.Start.ToString();
else if (tc.ParamType == "Interval") txtInterval.Text = tc.Start.ToString();
else if (tc.ParamType == "Resolution")
cboResolution.SelectedValue = tc.Start.ToString();
}
}
private void btncancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnok_Click(object sender, EventArgs e)
{
start = Convert.ToInt32(txtMinStartTraceStart.Text.Trim().ToString());
process = Convert.ToInt32(txtMinStartTraceProcess.Text.Trim().ToString());
end = Convert.ToInt32(txtMinStartTraceEnd.Text.Trim().ToString());
faceQuality = Convert.ToInt32(txtFaceQuality.Text.Trim().ToString());
faceConfidence = Convert.ToInt32(txtFaceConfidence.Text.Trim().ToString());
processIncrement = Convert.ToInt32(nudProcessIncrement.Value.ToString());
endIncrement = Convert.ToInt32(nudEndIncrement.Value.ToString());
interval = Convert.ToInt32(txtInterval.Text.Trim().ToString());
resolution = Convert.ToInt16(cboResolution.SelectedValue.ToString());
DBColection.updateConfigList(start, process, end, faceQuality, faceConfidence, processIncrement, endIncrement, interval, resolution);
}
private void cboResolution_SelectedIndexChanged(object sender, EventArgs e)
{
resolution = Convert.ToInt16(cboResolution.SelectedValue.ToString());
}
}
class TextAndValue
{
private string _RealValue = "";
private string _DisplayText = "";
public string DisplayText
{
get
{
return _DisplayText;
}
}
public string RealValue
{
get
{
return _RealValue;
}
}
public TextAndValue(string ShowText, string RealVal)
{
_DisplayText = ShowText;
_RealValue = RealVal;
}
public override string ToString()
{
return _RealValue.ToString();
}
}
}
展开全部
使用绑定数据集,如你要绑定的数据集为dv对象(DataView),其中包圆陆含ID和Name两列数据,分别为实际值和显埋腔销示文本弯游。combobox的对象名为cmb,实现代码如下:
cmb.DataSource=dv;
cmb.DisplayMember="Name";
cmb.ValueMember="ID";
cmb.DataBind();
cmb.DataSource=dv;
cmb.DisplayMember="Name";
cmb.ValueMember="ID";
cmb.DataBind();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
您好,很高兴为您解答!
思路如1,代码如2所示:
使用绑定数据集,如你要绑定的数据集为dv对象(DataView),其中包含ID和Name两列数据,分别为实际值和尘指显示文本。辩掘
combobox的对携兄核象名为cmb,实现代码如下:
cmb.DataSource=dv;
cmb.DisplayMember="Name";
cmb.ValueMember="ID";
cmb.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.comboBox1.DisplayMember = "裂汪好显示出来那个字段";
this.comboBox1.ValueMember = "这个是对应那个陵知value值,通常也就肆铅是id值";
this.comboBox1.DataSource=数据源;
接下来绑定数据
this.comboBox1.ValueMember = "这个是对应那个陵知value值,通常也就肆铅是id值";
this.comboBox1.DataSource=数据源;
接下来绑定数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你就写个结构体
struct Combo
{
string Show;
string Hide;
}
然后定义个此类型的数组碧行芹带圆,把你所有的配对都悔毕存进去。
struct Combo
{
string Show;
string Hide;
}
然后定义个此类型的数组碧行芹带圆,把你所有的配对都悔毕存进去。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询