C#中ComboBox选择后怎么获得我选择的combobox的值呢

比如有10203040这四个值如何选中20的时候怎么获得这个值?... 比如 有 10 20 30 40 这四个值 如何选中20的时候 怎么获得这个值? 展开
 我来答
隋蔓42
2011-08-12 · TA获得超过867个赞
知道小有建树答主
回答量:234
采纳率:0%
帮助的人:143万
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace publicClass.publicClass.other
{
public class ComBDa
{
private string _StrValue;
private string _StrText;
public ComBDa(string StrValue, String StrText)
{
_StrText = StrText;
_StrValue = StrValue;
}

//覆盖该方法是为了使该对象的值在下拉列表框中显示出来
public override string ToString()
{
return StrText;
}

public string StrValue
{
get { return _StrValue; }
set { _StrValue = value; }
}

public string StrText
{
get { return _StrText; }
set { _StrText = value; }
}
//通过键值得到描述
public static string getText(ComboBox pCob, string pKey)
{
foreach (object obj in pCob.Items)
{
ComBDa sc = (ComBDa)obj;
if (sc._StrValue == pKey)
{
pCob.Text = sc._StrText;
return sc._StrText;
}
}
return "";
}

//通过描述得到键值
public static string getKey(ComboBox pCob, string pText)
{
string txt = pText;
if (txt == null || txt == "")
{
if (pCob.SelectedIndex > -1)
{
ComBDa sc = (ComBDa)pCob.Items[pCob.SelectedIndex];
return sc._StrValue;
}
}
foreach (object obj in pCob.Items)
{
ComBDa sc = (ComBDa)obj;
if (sc._StrText == txt) return sc._StrValue;
}
return txt;
}
//pCob选中值为pvalue的哪一项
public static int getSelectIndex(ComboBox pCob, string pvalue)
{
int j = 0;
for (int i = 0; i < pCob.Items.Count; i++)
{
ComBDa sc1 = (ComBDa)pCob.Items[i];
if (sc1.StrValue == pvalue)
{
j = i;
break;
}
}
return j;

}
//pCob选中文本为ptext的哪一项
public static int getSelectIndexText(ComboBox pCob, string ptext)
{
int j = 0;
for (int i = 0; i < pCob.Items.Count; i++)
{
ComBDa sc1 = (ComBDa)pCob.Items[i];
if (sc1.StrText == ptext)
{
j = i;
break;
}
}
return j;

}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式