繁体   English   中英

c#组合框根据另一个组合框的值过滤一个组合框

[英]c# combobox filtering one combobox based on the value of another combobox

我有2个表格,product_items和category。 和2个组合框。 我要在选择类别之后过滤另一个组合框。 对不起,我的英语不好说:),我尝试了9h,但没有解决方案:/我的代码我写了多少。

DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter("select itemid, itemname, pcatid from produkti_items_tab", TestConnection);
            da.Fill(ds, "FillDropDown");

            comboBox1.DataSource = ds.Tables["FillDropDown"].DefaultView;
            comboBox1.DisplayMember = "itemname";
            comboBox1.ValueMember = "itemid";

            //============================================
            DataSet ddd = new DataSet();
            SqlDataAdapter dada = new SqlDataAdapter("select pcatid, pcatname from produkti_cat_tab", TestConnection);
            dada.Fill(ddd, "FillDropDownzzz");

            comboBox2.DataSource = ddd.Tables["FillDropDownzzz"].DefaultView;
            comboBox2.DisplayMember = "pcatname";
            comboBox2.ValueMember = "pcatid";

但是我不知道我应该在这里写些什么:

    private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
    //how filter :/
}

不确定,需要进行测试,但是绑定到第一个组合框的DataView具有RowFilter属性。
将此属性设置为适当的条件应删除不属于当前所选类别的项目

if(comboBox2.SelectedValue != null)
{
    DataView dv = comboBox1.DataSource as DataView;
    dv.RowFilter = "pcatid = " + comboBox2.SelectedValue.ToString();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM