GridLookUpEdit多列模糊查询最简单方式 z

GridLookUpEdit的知识库是RepositoryItemGridLookUpEdit,切确的说GridLookUpEdit只是RepositoryItemGridLookUpEdit的一个壳而已,
这也就是在GridControl的GridView中,对列绑定的是RepositoryItemGridLookUpEdit而不是GridLookUpEdit的原因,RepositoryItemGridLookUpEdit才是GridLookUpEdit的核心,所以处理这个过滤操作,其实就是对RepositoryItemGridLookUpEdit进行操作,
方法的参数也是RepositoryItemGridLookUpEdit类型,这样在GridView中使用RepositoryItemGridLookUpEdit也可以直接调用。eg:

SetGridLookUpEditMoreColumnFilter(gridLookUpEdit1.Properties);
SetGridLookUpEditMoreColumnFilter(repositoryItemGridLookUpEdit1);
/// <summary>
        /// 设置GridLookUpEdit多列过滤
        /// </summary>
        /// <param name="repGLUEdit">GridLookUpEdit的知识库,eg:gridlookUpEdit.Properties</param>
        void SetGridLookUpEditMoreColumnFilter(DevExpress.XtraEditors.Repository.RepositoryItemGridLookUpEdit repGLUEdit)
        {
            repGLUEdit.EditValueChanging += (sender, e) =>
            {
                this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => {
                    GridLookUpEdit edit = sender as GridLookUpEdit;
                    DevExpress.XtraGrid.Views.Grid.GridView view = edit.Properties.View as DevExpress.XtraGrid.Views.Grid.GridView;
                    //获取GriView私有变量
                    System.Reflection.FieldInfo extraFilter = view.GetType().GetField("extraFilter",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

                    List<DevExpress.Data.Filtering.CriteriaOperator> columnsOperators = new List<DevExpress.Data.Filtering.CriteriaOperator>();
                    foreach (GridColumn col in view.VisibleColumns)
                    {
                        if (col.Visible && col.ColumnType == typeof(string))
                            columnsOperators.Add(new DevExpress.Data.Filtering.FunctionOperator(DevExpress.Data.Filtering.FunctionOperatorType.Contains,
                                new DevExpress.Data.Filtering.OperandProperty(col.FieldName),
                                new DevExpress.Data.Filtering.OperandValue(edit.Text)));
                    }

                    string filterCondition = new DevExpress.Data.Filtering.GroupOperator(DevExpress.Data.Filtering.GroupOperatorType.Or, columnsOperators).ToString();

                    extraFilter.SetValue(view, filterCondition);
                    //获取GriView中处理列过滤的私有方法
                    System.Reflection.MethodInfo ApplyColumnsFilterEx = view.GetType().GetMethod("ApplyColumnsFilterEx", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    ApplyColumnsFilterEx.Invoke(view, null);
                }));

            };

        }

 

posted on 2017-01-04 19:36  武胜-阿伟  阅读(1139)  评论(1编辑  收藏  举报