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;
}
}
}
同求解。。
没看懂你干什么。。你说清楚流程