开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 4262|回复: 1

vb.net Devexpress lookupedit Multi-column filter 多更检索

[复制链接]

0

精华

13

贡献

81

赞扬

帖子
80
软币
569
在线时间
74 小时
注册时间
2015-3-20
发表于 2016-2-25 14:41:03 | 显示全部楼层 |阅读模式
本帖最后由 tunatic 于 2016-2-25 14:43 编辑

Devexpress lookupedit Multi-column filter
      在使用devexpress lookupedit中,有需要使用到多列过滤。例如,一个lookupedit中呈现的是产品的资料,在lookupedit中输入产品名称和拼音字母都可实现对产品的过滤。
lookupedit默认的是对某列过滤的。要实现多列过滤,需要另外写代码控管。代码如下:

[C#] 纯文本查看 复制代码
private void FilterLookup(object sender)
        {
 
            GridLookUpEdit edit = sender as GridLookUpEdit;
            GridView gridView = edit.Properties.View as GridView;
            FieldInfo fi = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic | BindingFlags.Instance);
            BinaryOperator op1 = new BinaryOperator("ProductName", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
            BinaryOperator op2 = new BinaryOperator("PinYin", "%" + edit.AutoSearchText + "%", BinaryOperatorType.Like);
            string filterCondition = new GroupOperator(GroupOperatorType.Or, new CriteriaOperator[] { op1, op2 }).ToString();
            fi.SetValue(gridView, filterCondition);
 
            MethodInfo mi = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic | BindingFlags.Instance);
            mi.Invoke(gridView, null);
        }
  private void lkpProductID_EditValueChanging(object sender, ChangingEventArgs e)
        {
            this.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate
            {
                FilterLookup(sender);
            }));
        }

在lkpProduct中输入的时候,触发lkpProductID_EditValueChanging事件,调用FilterLookup 方法。以下为vb代码:
[Visual Basic .NET] 纯文本查看 复制代码
Private Sub FilterLookup(ByVal sender As Object)

                        Dim edit As GridLookUpEdit = TryCast(sender, GridLookUpEdit)
                        Dim gridView As GridView = TryCast(edit.Properties.View, GridView)
                        Dim fi As FieldInfo = gridView.GetType().GetField("extraFilter", BindingFlags.NonPublic Or BindingFlags.Instance)
                        Dim op1 As New BinaryOperator("ProductName", "%" & edit.AutoSearchText & "%", BinaryOperatorType.Like)
                        Dim op2 As New BinaryOperator("PinYin", "%" & edit.AutoSearchText & "%", BinaryOperatorType.Like)
                        Dim filterCondition As String = (New GroupOperator(GroupOperatorType.Or, New CriteriaOperator() { op1, op2 })).ToString()
                        fi.SetValue(gridView, filterCondition)

                        Dim mi As MethodInfo = gridView.GetType().GetMethod("ApplyColumnsFilterEx", BindingFlags.NonPublic Or BindingFlags.Instance)
                        mi.Invoke(gridView, Nothing)
End Sub
  Private Sub lkpProductID_EditValueChanging(ByVal sender As Object, ByVal e As ChangingEventArgs)
                        Me.BeginInvoke(New System.Windows.Forms.MethodInvoker(Sub()
                                FilterLookup(sender)
                        End Sub))
  End Sub









回复

使用道具 举报

0

精华

0

贡献

16

赞扬

帖子
36
软币
506
在线时间
40 小时
注册时间
2014-7-16
发表于 2016-2-25 15:46:31 | 显示全部楼层

thanks----!
回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-12-23 11:14

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表