zoukankan      html  css  js  c++  java
  • comboBox dropdownlist droplist 添加 value

    1. public class ListItem   
    2. {   
    3.     private string _key = string.Empty;   
    4.     private string _value = string.Empty;   
    5.     public ListItem(string pKey, string pValue)   
    6.     {   
    7.         _key = pKey;   
    8.         _value = pValue;   
    9.     }   
    10.     public override string ToString()   
    11.     {   
    12.         return this._value;   
    13.     }   
    14.     public string Key   
    15.     {   
    16.         get  
    17.         {   
    18.             return this._key;   
    19.         }   
    20.         set  
    21.         {   
    22.             this._key = value;   
    23.         }   
    24.     }   
    25.     public string Value   
    26.     {   
    27.         get  
    28.         {   
    29.             return this._value;   
    30.         }   
    31.         set  
    32.         {   
    33.             this._value = value;   
    34.         }   
    35.     }   
    36. }   
    37.   
    38.   
    39. ///////////////////////////////////////////////////////////////   
    40. comboBox1.Items.Add(new ListItem("请选择""0"));   
    41. DataView dv = Comm.DB.ExecuteDataSet("select txtName,ID from dept where ParentID=24").Tables[0].DefaultView;   
    42. foreach (DataRowView drv in dv)   
    43. {   
    44.     comboBox1.Items.Add(new ListItem(drv["txtName"].ToString() , drv["ID"].ToString()));   
    45. }   
    46. comboBox1.DisplayMember = "Key";   
    47. comboBox1.ValueMember = "Value";   
    48. comboBox1.SelectedIndex = 0;   
    49.   
    50. ///////////////////////////////////////////////////////////////////   
    51.  MessageBox.Show(((ListItem)comboBox1.SelectedItem).Value); 
  • 相关阅读:
    2017 湖南省赛 K Football Training Camp
    一些相似单词的区别之处
    LeetCode301. Remove Invalid Parentheses
    算法刷题细节点总结
    LeetCode765. Couples Holding Hands
    LeetCode741. Cherry Pickup
    LeetCode312. Burst Balloons
    LeetCode679. 24 Game
    LeetCode862. Shortest Subarray with Sum at Least K
    LeetCode818. Race Car
  • 原文地址:https://www.cnblogs.com/liufei88866/p/1762647.html
Copyright © 2011-2022 走看看