vb.net Devexpress lookupedit Multi-column filter 多更检索
本帖最后由 tunatic 于 2016-2-25 14:43 编辑Devexpress lookupedit Multi-column filter
在使用devexpress lookupedit中,有需要使用到多列过滤。例如,一个lookupedit中呈现的是产品的资料,在lookupedit中输入产品名称和拼音字母都可实现对产品的过滤。
lookupedit默认的是对某列过滤的。要实现多列过滤,需要另外写代码控管。代码如下:
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代码: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
thanks----!
页:
[1]