绑定数据代码如下
if (ds != null && ds.Tables[0].Rows.Count > 0) //DataSet
{
    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
    {
        this.comboBox2.ValueMember = ds.Tables[0].Rows[i]["dict_id"].ToString();//取其中一列
        this.comboBox2.DisplayMember = ds.Tables[0].Rows[i]["dict_name"].ToString();//取其中一列
        
    }
}现在想在combobox开头加一项,但用代码this.comboBox2.Items.Insert(0,"全部")或是this.comboBox2.Items.Add("全部"),都不成功。
请问如何解决?谢谢!

解决方案 »

  1.   

    第二种方法应该是可行的。但是,可能是无法加在首部的如果你想要让它默认选择你输入的“全部”这一项,你可以尝试在items.add后,把selectedindex设置为最后一项
      

  2.   

    第2种试了,不行,提示绑定DataSource后无法修改。
    郁闷了;
      

  3.   

    this.comboBox2.Items.Add("全部");
    if   (ds   !=   null   &&   ds.Tables[0].Rows.Count   >   0)   //DataSet 

            for   (int   i   =   0;   i   <   ds.Tables[0].Rows.Count;   i++) 
            { 
                    this.comboBox2.Items.Add(Convert.ToString(ds.Tables[0].Rows[i]["dict_id"]));//取其中一列 
                    this.comboBox2.Items.Add(Convert.ToString(ds.Tables[0].Rows[i]["dict_name]));//取其中一列 
                    
            } 

      

  4.   

    注意Add方法的参数类型:
    this.Items.Add(0,new ListItem("全部",""));