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. VS2010错误

    1.用VS2010生成C++程序时,链接器工具错误 LNK1123: fatal error LNK1123: failure during conversion to COFF: file inva ...

  2. Python之路(第七篇)Python作用域、匿名函数、函数式编程、map函数、filter函数、reduce函数

    一.作用域 return 可以返回任意值例子 def test1(): print("test1") def test(): print("test") ret ...

  3. Fibonacci Number LT509

    The Fibonacci numbers, commonly denoted F(n) form a sequence, called the Fibonacci sequence, such th ...

  4. linux ubuntu R 无法安装rggobi包的原因及解决方案

    错误信息 Package'libxml-2.0',requiredby'ggobi',notfound     错误原因 ggobi缺乏libxml依赖 解决方案 sudo apt install l ...

  5. Java学习笔记:23种设计模式

    设计模式(Design pattern)的定义: In software engineering, a software design pattern is a general, reusable s ...

  6. 【算法】DP解决旅行路径问题

    问题描述 : After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best choice ...

  7. Django框架之models和不依赖Qquery的ajax请求

    一.models表字段 1)class表字段的创建 AutoField(Field) - int自增列,必须填入参数 primary_key=True BigAutoField(AutoField) ...

  8. Keras框架下使用CNN进行CIFAR-10的识别测试

    有手册,然后代码不知道看一下:https://keras-cn.readthedocs.io/en/latest/ 首先是下载数据集,下载太慢了就从网盘上下载: 链接:https://pan.baid ...

  9. python生成器初步了解

    一.生成器 生成器的本质就是迭代器    一个一个的创建对象   1.创建生成器的方式:    1.生成器函数 2.通过生成器表达式来获取生成器 3.类型转换 2.优点 节省内存 ,生成器本身就是代码 ...

  10. 2018.12.17 bzoj4802: 欧拉函数(Pollard-rho)

    传送门 Pollard−rhoPollard-rhoPollard−rho模板题. 题意简述:求ϕ(n),n≤1e18\phi(n),n\le 1e18ϕ(n),n≤1e18 先把nnn用Pollar ...