public class ListItem
{
private string _key = string.Empty;
private string _value = string.Empty;
public ListItem(string pKey, string pValue)
{
_key = pKey;
_value = pValue;
}
public override string ToString()
{
return this._value;
}
public string Key
{
get
{
return this._key;
}
set
{
this._key = value;
}
}
public string Value
{
get
{
return this._value;
}
set
{
this._value = value;
}
}
}
///////////////////////////////////////////////////////////////
comboBox1.Items.Add(new ListItem("请选择", "0"));
DataView dv = Comm.DB.ExecuteDataSet("select txtName,ID from dept where ParentID=24").Tables[0].DefaultView;
foreach (DataRowView drv in dv)
{
comboBox1.Items.Add(new ListItem(drv["txtName"].ToString() , drv["ID"].ToString()));
}
comboBox1.DisplayMember = "Key";
comboBox1.ValueMember = "Value";
comboBox1.SelectedIndex = 0;
///////////////////////////////////////////////////////////////////
MessageBox.Show(((ListItem)comboBox1.SelectedItem).Value);
引用本页地址: http://www.yongfa365.com/item/comboBox-dropdownlist-droplist-Tian-Jia-value.html
|
相关链接
|
|
| |
文章分类 |
|
|
|