http://bbs.csdn.net/topics/390536919

关于 cxGrid 的过滤问题 [问题点数:20分,结帖人zhengyc653]

           
不显示删除回复
           
显示所有回复
           
显示星级回复
           
显示得分回复
           
只显示楼主
          收藏
 
zhengyc653 

 
结帖率:95.45%
本帖最后由 zhengyc653 于 2013-08-03 15:17:16 编辑
 

今天用了一下cxGrid的过滤功能,非常强大,非常喜欢!
可是有一个缺点,他的运算符里面只有 like ,没有包含。
比如:我要找一个姓名包含‘国’字的人。
运算符必须得选 like 表达式则是:%国%
这样很多人就不懂得用了。

如何使它无需加%%就能过滤出名字包含'国'的人?

 
发表于: 2013-08-03 15:14:15 楼主

回复次数:14

CSDN推荐
董董 

 
用户输入“国”,你的代码就要包上%号。
回复于: 2013-08-03 15:23:17#1 得分:0

 
zhengyc653 

 
引用 1 楼 ddqqyy 的回复:

用户输入“国”,你的代码就要包上%号。

关键是在哪里的代码加上%号?

回复于: 2013-08-03 15:38:26#2 得分:0

 
董董 

 
用户输入查询条件之后,一般都要再点击一个“查询”按钮才开始查询吧?

你就在按钮事件中加%嘛。

回复于: 2013-08-03 15:45:31#3 得分:0

 
zhengyc653 

 
引用 3 楼 ddqqyy 的回复:

用户输入查询条件之后,一般都要再点击一个“查询”按钮才开始查询吧?

你就在按钮事件中加%嘛。

这个查询对话框要cxGrid自带的,不是我们自己设计的啊

回复于: 2013-08-03 15:47:52#4 得分:0

 
22222bbb 

 
二楼没明白楼主的意思。同求解决方法
回复于: 2013-08-03 15:52:58#5 得分:0

 
zhengyc653 

 
自己顶一下.... 难道没人遇到这个问题?
回复于: 2013-08-06 08:26:33#6 得分:0

 
simonhehe 

 
  
lz的需求, 只能改dev的代码实现

like的匹配情况有: %国%   国%   %国
你需求的[包含], 匹配情况只有: %国%

回复于: 2013-08-06 10:24:08#7 得分:0

 
zhengyc653 

 
引用 7 楼 simonhehe 的回复:

lz的需求, 只能改dev的代码实现

like的匹配情况有: %国%   国%   %国
你需求的[包含], 匹配情况只有: %国%

我也不知道要改Dev的代码,可跟踪来跟踪去,就是不知道要在哪改!

回复于: 2013-08-06 10:41:35#8 得分:0

 
zhengyc653 

 
思路:
应该在过滤窗体中找到确定这个按钮,然后更改生成出来的过滤字串。
于是,找到 cxFilterControlDialog.pas  ,查看 OK 按钮的 OnClick 事件
发现里面只有一条语句: 
ApplyFilter;
于是,再跟踪 ApplyFilter 函数,它的声明如下: 
procedure ApplyFilter; virtual;

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
procedure TfmFilterControlDialog.ApplyFilter;
begin
  SetControlsEnabled(False);
  DoBeforeApply;
  try
    FilterControl.ApplyFilter;
  finally
    DoAfterApply;
    SetControlsEnabled(True);
  end;
end;

继续跟踪 DoBeforeApply ,发现其也是一个虚方法:

Delphi/Pascal code

 

?

1
2
3
4
5
procedure TfmFilterControlDialog.DoBeforeApply;
begin
  if Assigned(FOnBeforeApply) then
    FOnBeforeApply(Self);
end;

又发现 FOnBeforeApply 的声明为:
FOnBeforeApply: TNotifyEvent;
到这,就不懂得如何往下跟踪了...  

回复于: 2013-08-06 10:53:58#9 得分:0

 
zhengyc653 

 
filterControl.ApplyFilter;
filterControl 这个对象在哪? 在这个单元好像没找到这个对象
不知道是引引哪个单元的东东
回复于: 2013-08-06 11:02:16#10 得分:0

 
simonhehe 

 
  
1 把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxFilter.pas

2 TcxFilterCriteria.AddItem过程做如下修改:(自动给like, not like运算的查询条件加%)

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
12
function TcxFilterCriteria.AddItem(AParent: TcxFilterCriteriaItemList; AItemLink: TObject;
  AOperatorKind: TcxFilterOperatorKind; const AValue: Variant;
  const ADisplayValue: string): TcxFilterCriteriaItem;
begin
  if AParent = nil then
    AParent := Root;
 
  if AOperatorKind in [foLike, foNotLike] then
    Result := AParent.AddItem(AItemLink, AOperatorKind, '%' + AValue + '%', ADisplayValue)
  else
    Result := AParent.AddItem(AItemLink, AOperatorKind, AValue, ADisplayValue);
end;
回复于: 2013-08-06 17:52:49#11 得分:0

 
zhengyc653 

 
引用 11 楼 simonhehe 的回复:

1 把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxFilter.pas

2 TcxFilterCriteria.AddItem过程做如下修改:(自动给like, not like运算的查询条件加%)

Delphi/Pascal code

 

?

1
2
3
4
5
6
7
8
9
10
11
12
function TcxFilterCriteria.AddItem(AParent: TcxFilterCriteriaItemList; AItemLink: TObject;
  AOperatorKind: TcxFilterOperatorKind; const AValue: Variant;
  const ADisplayValue: string): TcxFilterCriteriaItem;
begin
  if AParent = nil then
    AParent := Root;
 
  if AOperatorKind in [foLike, foNotLike] then
    Result := AParent.AddItem(AItemLink, AOperatorKind, '%' + AValue + '%', ADisplayValue)
  else
    Result := AParent.AddItem(AItemLink, AOperatorKind, AValue, ADisplayValue);
end;

非常感谢这位仁兄的帮助,问题解决了一半,按照你的方法,确实可行,但只适用于这个界面:

对于下面这个界面没有效果:

回复于: 2013-08-06 22:56:45#12 得分:0

 
simonhehe 

 
  
之前的修改全部取消.

一下改动完成后, 所有使用该文件做过滤的, like, not like 都会受影响
-------------------------------------------------------
把这个文件复制到你的程序目录
\DevExpress VCL\ExpressDataController\Sources\cxLike.pas

function LikeStr(const AStr, APatternStr: string; APercent, AUnderline: Char): Boolean;
var
  vPatternStr : string;
begin
  vPatternStr := Format('%%%s%%', [APatternStr]);
  Result := Like(PChar(AStr), Length(AStr), PChar(vPatternStr),
    Length(vPatternStr), APercent, AUnderline, #0);
end;

回复于: 2013-08-07 09:14:21#13 得分:20

 
zhengyc653 

 
非常感谢 simonhehe 的热心助助!!问题解决,分不多,全给你了。

关于 cxGrid 的过滤问题的更多相关文章

  1. cxgrid取消过滤下拉框

    选择tableview1.optionscustomize.columnfiltering=fasle;

  2. cxgrid的过滤%x%问题【备查】

    把这个文件复制到你的程序目录\DevExpress VCL\ExpressDataController\Sources\cxLike.pas function LikeStr(const AStr,  ...

  3. cxgrid过滤使用心得

    uses cxFilter; cxgrid过滤条件清除:cxgrdbtblvwGrid1DBTableView2.DataController.Filter.AutoDataSetFilter:=Tr ...

  4. cxgrid属性说明,每次用的时候费时费力查找。

    由层得到数据表名: procedure TFB_PatientWaiting.cxgrdbtblvwGrid1DBTableView_MyPatienWaitingDblClick( Sender: ...

  5. cxGrid控件过滤筛选后如何获更新筛选后的数据集

    cxGrid控件过滤筛选后如何获更新筛选后的数据集 (2015-06-19 12:12:08) 转载▼ 标签: delphi cxgrid筛选数据集 cxgrid过滤 分类: Delphi cxGri ...

  6. cxGrid实现取消过滤和排序后定位到首行(单选和多选)

    cxGrid实现取消过滤和排序后定位到首行(单选和多选) 原创 2013年10月06日 18:42:24 2107 DataContoller中的函数FocusedRecordIndex没有反应,Fo ...

  7. cxGrid控件过滤排序和TClientDataSet同步

    https://www.cnblogs.com/false/archive/2013/02/24/2924240.html procedure TReport10Form.cxGridViewData ...

  8. 如何访问cxGrid控件过滤后的数据集

    var I: Integer; begin Memo1.Lines.Clear; with cxGrid1DBTableView1.DataController do for I := 0 to Fi ...

  9. CXGrid的使用技巧

    CXGrid的使用技巧 ========================================================================== 在主从TableView中 ...

随机推荐

  1. LocalStorage的一些使用

    LocalStorage是什么 LocalStorage 是在Html5中出现的一种本地存储.说到本地存储,大家立马会联想到Cookie,还有SqlLite. LocalStorage 中的数据不会像 ...

  2. 20岁的设计师vs30岁的设计师

    20岁的设计师vs30岁的设计师 如果你还是20来岁,要恭喜你,你还年轻, 一切才刚刚开始 还有时间去探索无尽的可能 还有时间去找到无限的前途 ​ 如果30岁的你还不够强大, 请记得时刻给予自己信心, ...

  3. Java 使用 jacob 将 word 文档转换为 pdf 文件

    网上查询了许许多多的博客,说利用 poi.iText.Jsoup.jdoctopdf.使用 jodconverter 来调用 openOffice 的服务来转换等等,我尝试了很多种,但要么显示不完全, ...

  4. OCIlib的几个函数的执行效率(附上pro*c的性能对比)

    ocilib提供了以下几个执行sql语句的函数 OCI_ExecuteStmt/OCI_ExecuteStmtFmt 使用没有绑定变量的语句 OCI_Execute 使用有绑定变量的语句 OCI_Im ...

  5. 《C#从现象到本质》读书笔记(一)第1章 .NET基础知识

    最近根据博客园大神的推荐,买了本<C#从现象到本质>.做一点读书笔记. 由于不懂IL和ildasm,winddg,太深奥,理解不了,就牛嚼草一样,先总结第一遍读书,自己总结的知识点了.不知 ...

  6. 利用PHPExcel读取excel文件

    $filePath = "7788.xls"; $PHPExcel = new PHPExcel(); $PHPReader = new PHPExcel_Reader_Excel ...

  7. 一个机器上运行两个tomcat

    一.   在一台计算机上配置2个tomcat是可以的,关键是tomcat里的server.xml文件中三个端口必须不同.需要修改conf/server.xml使两个tomcat占用的端口不相同,在缺省 ...

  8. 【Apache】Apache服务的基本概念(二)

    Apache服务的基本概念 Apache安装请参照:[Apache]Apache服务的安装(一) 1.端口 apache默认监听TCP协议端口80端口 2.apache服务 apache服务默认会启动 ...

  9. day06作业---字典循环

    '''1.1使⽤循环打印以下效果: ***************''' for a in range(1,6): print(a*'*') '''1.2: ***** **** *** ** * ' ...

  10. NOIP 2017 d2t2 70points

    革命之路漫漫 第一次尝试 40points spfa #include <bits/stdc++.h> #define read read() using namespace std; i ...