带有查询的Combobox droplist项目选择 [英] Combobox droplist item picking with query

查看:65
本文介绍了带有查询的Combobox droplist项目选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个组合框,comboBox1项是从数据绑定中获取的(table1Root包含ID和Root,table2Parent包含ID,Parent,RootID)。 comboBox2的项目列表取决于comboBox1中的选定值..问题是,我无法过滤comboBox2.Displaymember ..请帮忙,这是我的代码:



i have 2 combo box, comboBox1 item was taken from databinding(table1"Root" contains ID and Root, table2"Parent" contains ID, Parent, RootID). The item list for comboBox2 are depends on selected value from comboBox1.. the problem is, i can't filter the comboBox2.Displaymember.. please help, here is my codes:

private void comboBox2_DropDown(object sender, EventArgs e)
        {
            cn.Open();
            //comboBox2.DataSource = parentBindingSource;
            SqlCommand cb2 = new SqlCommand("SELECT * FROM PARENT WHERE RootID = " + comboBox1.SelectedValue.ToString(), cn);
            SqlDataAdapter dat = new SqlDataAdapter(cb2);
            DataSet ds = new DataSet();
            dat.Fill(ds, "Parent");
            comboBox2.DataSource = ds;
            cn.Close();
        }





请帮助..



Please help..

推荐答案

comboBox2 .DataSource = ds;

comboBox2.DisplayMember =ColumnName1;

comboBox2.ValueMember =ColumnName2;
comboBox2.DataSource = ds;
comboBox2.DisplayMember = "ColumnName1";
comboBox2.ValueMember = "ColumnName2";


这篇关于带有查询的Combobox droplist项目选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆