2 tjlgx2008 tjlgx2008 于 2014.10.17 11:20 提问

需要实现一个3级联动,绑定和过滤都没问题,就是主表过滤后不能刷新显示怎么办?

要实现一个三级联动的功能:一个TreeList,根据当前节点的信息生成条件过滤,主表tbKH,其他三个表是客户的子表通过主键关联绑定。主表和子表都绑定联动没问题,现在点击TreeList节点生成条件过滤tbKH表也没问题,但是过滤后怎么刷新显示被难住了,已知刷新显示的方法都无法保证 主表与子表的关联继续生效,怎么解决,跪谢高人…… 以下是代码:

        //将填充好的表格加入DataSet
        dsKH = new DataSet();
        DataTable[] tb = { tbKH, tbContactInfo, tbCustomerBank, tbContactCustomerHis };
        dsKH.Tables.AddRange(tb);

         //给主表和子表格建立主键关联
        dsKH.Relations.Add("KH_ContactInfo", tbKH.Columns["id"], tbContactInfo.Columns["cid"]);
        dsKH.Relations.Add("KH_CustomerBank", tbKH.Columns["id"], tbCustomerBank.Columns["cid"]);
        dsKH.Relations.Add("KH_ContactCustomerHis", tbKH.Columns["id"], tbContactCustomerHis.Columns["cid"]);


        BS = new BindingSource();
        BS.DataSource = dsKH;
        //BS.DataMember = "CustomerInfo";
        //给网格绑定数据源
        grdCustomerInfo.DataSource = BS;
        grdCustomerInfo.DataMember = "CustomerInfo";

        this.grdBankInfo.DataSource = BS;
        grdBankInfo.DataMember = "CustomerInfo.KH_CustomerBank";

        grdContactInfo.DataSource = BS;
        grdContactInfo.DataMember = "CustomerInfo.KH_ContactInfo";

        grdCustomerTrack.DataSource = BS;
        grdCustomerTrack.DataMember = "CustomerInfo.KH_ContactCustomerHis";

这一块是绑定主表和子表都没有问题,

public void FilterKHByTree(Dictionary wInfo)
{
string where =string.Empty;
foreach (KeyValuePair kvp in wInfo)
{
if (!string.IsNullOrEmpty (where)) where += " and ";
where += "CustomerInfo."+GetEmnuFieldName(kvp.Key) + " = '" + kvp.Value+"'";
}
BS.Filter = where;
BS.ResetBindings(true);
//dsKH.Tables["CustomerInfo"].DefaultView.RowFilter = where; ;
gvCustomerInfo.RefreshData();
//BS.Filter = where;
//BS.ResetBindings(true);
//gvCustomerInfo.ActiveFilter.NonColumnFilter = where;

        //GridView view = new GridView();
        //DataView dv = gvCustomerInfo.DataSource as DataView;
        //dv.RowFilter = where;

        //DataView dv = dsKH.Tables["CustomerInfo"].AsDataView();
        //dv.RowFilter = where;


        //dsKH.Tables["CustomerInfo"].Select(where);
       // grdCustomerInfo.BindingContext[dsKH].EndCurrentEdit (); 

       //dsKH.Tables["CustomerInfo"].DefaultView.RowFilter = where;

        //grdCustomerInfo.DataSource =dsKH;
        //grdCustomerInfo.DataMember = "CustomerInfo";

        //gvCustomerInfo.  = tbKH;
    }

这一块就是我试过的过滤刷新方法

Csdn user default icon
上传中...
上传图片
插入图片