谁有给CombBox加上Text和Value的值,然后分别读出(特别是Value)的值 的最简单的例子? 兄弟,你value加上值了后,要再选中才行,否则会出现你上面的错误。取当前值用this.comboBox1.text 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样试试:string valueStr;if (this.comboBox1.SelectedIndex != -1) valueStr = this.comboBox1.SelectedValue.ToString();如果还不行,把出问题的语句包在try中,调试一下,看看异常信息。 this.comboBox6.DataSource = ds.Tables["种类"].DefaultView; this.comboBox6.DisplayMember = "种类名称"; this.comboBox6.ValueMember = "种类编号";******************************************************if (this.comboBox6.SelectedIndex != -1)int num = Convert.ToInt32(this.comboBox6.SelectedValue); 写个类封装VALUE和TEXT就可以了:public class CItem{ private int m_v; private string m_t; public CItem(int v, string t) { m_v=v; m_t=t; } public override string ToString() { return m_t; } public int Value() { return m_v; }}//添加到COMBOBOX中this.comboBox1.Items.Add(new CItem(1, "aaa"));this.comboBox1.Items.Add(new CItem(2, "bbb"));//读出VLAUE和TEXTCItem Item=(CItem)this.comboBox1.SelectedItem;MessageBox.Show(Item.ToString());MessageBox.Show(Item.Value().ToString()); 不要读取数据库里的,那怕是得到了text value之后,那如何把 value读取出来呢? 如何阻止某个软件的安装 寻找高手,解决问题 熟悉.net Remoting的高手请帮忙!简单问题:如何从服务器端返回string! 怎么在VS2005中进行加密及解密? 反射取property值得问题。高分请教! 如何在LABEL控件中绘图 DataGird中怎么在指定列加入CheckBox控件 字符串写入文本文件时 换行符的问题? 如何动态的定义事件,如何订阅动态事件 ***如何给textbox添加"Enter"键事件*** 怎样将参数传递到程序中 请问在代码中如何判断某控件的某事件是否发生?
if (this.comboBox1.SelectedIndex != -1)
valueStr = this.comboBox1.SelectedValue.ToString();如果还不行,把出问题的语句包在try中,调试一下,看看异常信息。
this.comboBox6.DisplayMember = "种类名称";
this.comboBox6.ValueMember = "种类编号";
******************************************************
if (this.comboBox6.SelectedIndex != -1)
int num = Convert.ToInt32(this.comboBox6.SelectedValue);
public class CItem
{
private int m_v;
private string m_t; public CItem(int v, string t)
{
m_v=v;
m_t=t;
}
public override string ToString()
{
return m_t;
} public int Value()
{
return m_v;
}}//添加到COMBOBOX中
this.comboBox1.Items.Add(new CItem(1, "aaa"));
this.comboBox1.Items.Add(new CItem(2, "bbb"));//读出VLAUE和TEXT
CItem Item=(CItem)this.comboBox1.SelectedItem;
MessageBox.Show(Item.ToString());
MessageBox.Show(Item.Value().ToString());