定義一個(gè)類,,有兩個(gè)屬性
/// <summary>
/// 元數(shù)據(jù) /// </summary> [System.Diagnostics.DebuggerStepThrough] [Serializable] public class SandData { String key = ""; Object value = ""; /// <summary> /// 元數(shù)據(jù) /// </summary> public SandData() { } /// <summary> /// 元數(shù)據(jù) /// </summary> public SandData(String m_key,Object m_value) { this.key = m_key; this.value = m_value; } public String Key { get { return key; } set { key = value; } } public Object Value { get { return this.value; } set { this.value = value; } } } 然后,用一個(gè) ArrayList list = new ArrayList();
foreach (DataRow row in table.Rows) { string text = row["d_name"].ToString() +"[" + row["UptownName"].ToString() + row["BuildingName"].ToString() + row["UnitName"].ToString()+"]"; string value = row["Id"].ToString(); SandData vo = new SandData(); vo.Key = text; vo.Value = value; list.Add(vo); } this.comboBox1.DataSource = list; this.comboBox1.DisplayMember = "Key"; this.comboBox1.ValueMember = "Value"; 這樣就OK了,,取值只要cbb.SelectedValue就取到了。
|
|
來(lái)自: 務(wù)實(shí)耐久 > 《待分類1》