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);

转载于:https://www.cnblogs.com/zeng-qh/p/7354453.html

你可能感兴趣的:(winfrom动态绑定下拉框)