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. HDU 3861.The King’s Problem 强联通分量+最小路径覆盖

    The King’s Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Python之路(第二十五篇) 面向对象初级:反射、内置方法

    [TOC] 一.反射 反射的概念是由Smith在1982年首次提出的,主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省).这一概念的提出很快引发了计算机科学领域关于应用反射性的研究.它 ...

  3. Python之路(第二十一篇) re模块

    一.re模块 正则表达式本身是一种小型的.高度专业化的编程语言,正则表达式就是字符串的匹配规则,在多数编程语言里都有相应的支持,python里对应的模块是re,正则表达式模式被编译成一系列的字节码,然 ...

  4. UVA 10405 Longest Common Subsequence

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&p ...

  5. 【算法】BFS+哈希解决八数码问题

    15拼图已经有超过100年; 即使你不叫这个名字知道的话,你已经看到了.它被构造成具有15滑动砖,每一个从1到15上,并且所有包装成4乘4帧与一个瓦块丢失.让我们把丢失的瓷砖“X”; 拼图的目的是安排 ...

  6. python下使用opencv拍照

    首先在命令中安装opencv: pip install opencv-python 然后打开notebook: jupyter notebook 建立文件,写入如下代码: import cv2 cap ...

  7. Servlet中(Session、cookies、servletcontext)的基本用法

    /req: 用于获得客户端(浏览器)的信息 //res: 用于向客户端(浏览器)返回信息 1.session的设置:            //得到和req相关联的session,如果没有就创建ses ...

  8. tomat修改启动路径

    https://blog.csdn.net/axela30w/article/details/76546735

  9. c#用EPPLUS操作excel

    参考: http://www.cnblogs.com/rumeng/p/3785748.html http://www.cnblogs.com/libla/p/5824296.html#3818995 ...

  10. MODULE_DEVICE_TABLE 的作用

    pci_device_id,PCI设备类型的标识符.在include/linux/mod_devicetable.h头文件中定义.struct pci_device_id {        __u32 ...