Winform里有关Combobox的一些操作

来源:互联网 发布:iis7端口设置 编辑:程序博客网 时间:2024/05/02 02:29
读取其内容值(value):this.cobobox1.SelectedValue.ToString()

读取其显示值(text):this.cobobox1.SelectedText.ToString()


与查询数据库结果绑定:

//sql语句

 string sql_ShuM = " select " + changyongziliaoEntity.ID + " as ID "
                + "," + changyongziliaoEntity.cMC + " as 属名 "
                    + "  from " + changyongziliaoEntity.tName
                    + " where " + changyongziliaoEntity.nZT + "=1 and " + changyongziliaoEntity.cLB + "='shu'";

 OleDbDataAdapter oleZhongM = new OleDbDataAdapter(sql_ShuM, oleCon);
                     DataTable dtShuM = new DataTable();


                     oleZhongM.Fill(dtShuM);
                     this.comboBox2.DataSource = dtShuM.DefaultView;

                     this.comboBox2.DisplayMember = "属名";
                     this.comboBox2.ValueMember = "ID";

给ComboBox赋值:

this.diqu_comboBox.Items.Add("--请选择--");
                     this.diqu_comboBox.Items.Add("--湛江市--");
                     this.diqu_comboBox.Items.Add("--廉江市--");
                     this.diqu_comboBox.Items.Add("--雷州市--");
                     this.diqu_comboBox.Items.Add("--徐闻县--");
                     this.diqu_comboBox.Items.Add("--吴川市--");
                     this.diqu_comboBox.Items.Add("--遂溪县--");


0 0
原创粉丝点击