这样可以添加元素:
=============================
for( int i = 0; i < this.ds.Tables[table_name].Rows.Count; i++)
{
cb.Items.Add(this.ds.Tables[table_name].Rows[i][1].ToString());
}===============================
但是如果想给元素添加对应的值该怎么写呢?类似网页中的
“<select><option value="xx">text</option></select>”中的xx
多谢~~

解决方案 »

  1.   

    this.ddlXq_id.Items.Clear();
    ArrayList array2 = new ArrayList();
    ArrayList array1 = Pub.GetCol1("SELECT [ID],[NAME] FROM TABLE_XQ_PARA",ref array2);
    for(int i=0;i<array1.Count;i++)
    {
    this.ddlXq_id.Items.Add(array2[i].ToString().Trim());
    this.ddlXq_id.Items[i].Value = array1[i].ToString().Trim();
    }
      

  2.   

    2楼的兄弟,我这里报错,说没有value这个属性,我的程序是在winform中的~~~
      

  3.   

    cs中的comboBox好像是没有value的吧
      

  4.   

    不好意思哦,我那个是WEB的,WINFORM的不是很清楚了
      

  5.   

    Winform里面的ComboBox只有绑定的时候才能设定Text和Value
    用items.add()是没有办法设定Value的
      

  6.   

    public class ItemVO : System.Object
    {
    public string id;
    public string desc;

    public ItemVO(string Id, string Desc)
    {
    this.id = Id;
    this.desc = Desc;
    } public override string ToString() 
    {
    return this.desc;
    } public override bool Equals(System.Object obj) 
    {
    if (this.GetType().Equals(obj.GetType())) 
    {
    ItemVO that=(ItemVO) obj;
    return (this.id.Equals(that.id));
    }
    return false;
    }
    public override int GetHashCode()
    {
    return this.id.GetHashCode();;
    }
    }================
    comboBox1.Items.Add(new ItemVO(id,name));
      ((ItemVO)comboBox1.SelectedItem).id 
      ((ItemVO)comboBox1.SelectedItem).desc
      

  7.   

    如此添加成对的值;
    ArrayList list = new ArrayList();
       list.Add (new DictionaryEntry ("1","投诉"));
       list.Add (new DictionaryEntry ("2","举报"));
       list.Add (new DictionaryEntry ("3","建议"));
       list.Add (new DictionaryEntry ("4","表扬"));
       list.Add (new DictionaryEntry ("5","其它"));
       
       cbBoxLeiXing.DataSource =list;          
       cbBoxLeiXing.DisplayMember ="Value";
       cbBoxLeiXing.ValueMember ="Key";