簡體   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