winForm中绑定ComboBox下拉框

     1.用数组绑定   

           //以下为下拉框绑定数据源
            DataSet dsWarning=new DataSet();
            string cmdText = "Select CompanyID From Company";
            dsWarning = clsCommond.returnDataSet(para, cmdText, clsCommond.sqlType.Text);//访问数据库
            ArrayList listCompanyID = new ArrayList();  //ArrayList实现了IList接口,可直接做ComboBox控件的数据源
            for (int i = 0; i < dsWarning.Tables[0].Rows.Count; i++)
            {
                listCompanyID.Add(dsWarning.Tables[0].Rows[i][0].ToString());
            }
            listCompanyID.Insert(0, "全部");   //在数组的最前面插入一个元素(第0个元素)
            cmbbxCompanyID.DataSource = listCompanyID;
            dsWarning.Dispose(); 

你可能感兴趣的:(winForm中绑定ComboBox下拉框)