Fork me on GitHub

winfrom动态绑定下拉框

//动态绑定下拉框
            string sql = "select id ,name form B ";
            DataTable dt = DBHelper.GetDataTable(sql);
            //绑定数据源
            this.comboBox1.DataSource = dt;
            //绑定要显示的文本的字段
            this.comboBox1.DisplayMember = "name";
            //绑定真实的值value
            this.comboBox1.valueMember = "id";
           
            //弹出下拉框的值或文本

            string name = this.comboBox1.Text;
            string id = this.comboBox1.SelectdValue.ToString();
            MessageBox.Show(name);

posted @ 2017-08-13 19:33  都一样*  阅读(585)  评论(0编辑  收藏  举报