首页 > 其他分享 >delphi dev cxgrid 列绑定Richedti 支持过滤

delphi dev cxgrid 列绑定Richedti 支持过滤

时间:2024-07-13 18:19:10浏览次数:6  
标签:begin end AItem Richedti delphi cxgrid 过滤 AText TcxRichEditProperties

默认是不支持过滤的,这里需要改到内部的一些源码文件。

先说思路:

1.要让列支持过滤需要重载richedit类的 GetSupportedOperations,

type
  TcxRichEditProperties = class(cxRichEdit.TcxRichEditProperties)
  public

    function GetSupportedOperations: TcxEditSupportedOperations; override;
  end;
{ TcxRichEditProperties }

function TcxRichEditProperties.GetSupportedOperations: TcxEditSupportedOperations;
begin
  Result := [esoAutoHeight, esoEditing, esoHorzAlignment, esoFiltering]; //多加上 esoFiltering
end;

然后指定列为:  Column.PropertiesClass := TcxRichEditProperties; 不指定,直接设置的话是没有效果的。

要在过滤的时候能输入,需要处理一下GetProperties。放一个 cxEditRepository ,添加一个 RichItem  一个TextEditItem

procedure TForm1.ColumnGetProperties(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AProperties: TcxCustomEditProperties);
begin
  if ARecord is TcxGridFilterRow then
  begin
   AProperties := cxdtrpstrytxtmcxdtrpstry1TextItem1.Properties;
  end
  else
  begin
   AProperties := cxdtrpstry1RichItem1.Properties;
  end;
end;

还要处理,下拉过滤选择显示的问题,不处理。选择某一个过滤条件后。显示的是RTF格式的内容

procedure TForm1.ColumnGetDisplayText(
  Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
  var AText: String);
begin
 if AText = ''  then
  Exit;
 if ARecord is TcxGridFilterRow then
  if IsRichText(AText) then
    AText := ConvertRichText(AText);
end;

接下来是核心过滤的改动,cxfilter.pas文件 Compare 函数 .这里只贴 

Result := AItem.Operator.CompareValues(V, V2); 
之前要处理的代码。需要uses cxRichEdit, cxGridCustomTableView 这两个单元。判断过滤列是不是 TcxRichEditProperties 然后把RTF 转成纯文本就可以过滤了
   function IsRichText(const AText: string): Boolean;
   const
     ARichPrefix = '{\rtf';
   begin
     Result := Copy(AText, 1, Length(ARichPrefix)) = ARichPrefix;
   end;


  function Compare(AItem: TcxFilterCriteriaItem): Boolean;
  var
    V,V2: Variant;
  begin
    try

       if AItem.ItemLink <> nil then
       begin
        if AItem.ItemLink is TcxCustomGridTableItem then
        begin
         if TcxCustomGridTableItem(AItem.ItemLink).PropertiesClassName = 'TcxRichEditProperties' then
          if not IsRichText(v2) then //一般不可能输入rtf 格式的内容。 这里会触发的就是选过滤下拉选项那些
          V := ConvertRichText(V);  //转换后只剩下纯文本
        end;
       end;
       Result := AItem.Operator.CompareValues(V, V2);
      end;
    
  end;

 效果:

 

标签:begin,end,AItem,Richedti,delphi,cxgrid,过滤,AText,TcxRichEditProperties
From: https://www.cnblogs.com/BTag/p/18300461

相关文章

  • Delphi FMX跨平台框架
     一、前言    传统老Delphi人员大部分基本都是C/S端(客户端)开发上手(基于Windows开发),而FMX是Delphi中用于创建跨平台图形用户界面的框架。它允许开发人员使用单个代码库创建适用于多个操作系统的应用程序,如Windows、macOS、iOS和Android。FMX提供了丰富的界面控件和视......
  • Delphi LDAP对象管理(用户登录认证、组、组织)
    unitlogin;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,uniGUITypes,uniGUIAbstractClasses,uniGUIClasses,uniGUIRegClasses,uniGUIForm,uniButton,uniGUIBaseClasses,uniEdit,REST.Types,uniMemo,REST.Client,......
  • Delphi 常用控件之TlistView总结
    TlistView组件功能:(1)TListView控件可以用来显示各项带图标的列表,包括大图标和小图标的;也可以用来显示带有子项的列表,Windows操作系统的资源管理器中文件夹窗口就是最好的应用例子,就是我们打开"我的电脑"后能够看到各个盘符的界面(2)TListView控件基本能实现和DBGrid控件一......
  • delphi BDE Reader 不需要驱动
    用过Delphi开发的几乎都知道BDE,是读取paradoxDB(*.db)数据库(表)读取的驱动。要存取数据,必需安装BDE驱动程序,才能正常读取,还需要配置,发布程序就更不方便,所以吐槽的很多。如果升级成64位程序,几乎只有放弃,因为没有64位的BDE驱动[官方己说明](可以在64位的windows系统上安装,但B......
  • 在delphi用移动鼠标左键配合shift的方法选择部分文字
    procedureTForm1.ButtonPen1Click(Sender:TObject);beginSetCursorPos(694,352);//设置开始的位置。Sleep(300);//mouse_event(MOUSEEVENTF_RIGHTDOWN,0,0,0,0);//模拟按下鼠标右键。//mouse_event(MOUSEEVENTF_RIGHTUP,0,......
  • Delphi换行_这里只换一行
    开发环境DelphiXe11;这个代码不适用于Delphi7,一般不适用于Delphi2007之前的版本;这个图片:12个字(汉字)换行;2数字和2字母认为等于1汉字;这个换行不大行,全是小写的字母占占用的位置比较少,如果要效果好的,请自己写;  --Unit-- unitUnit1;interfaceusesWinapi.Windows......
  • delphi Image32 变形控制
    先看动画:  代码:1unituFrmTransform;23interface45uses6Winapi.Windows,Winapi.Messages,System.SysUtils,System.Variants,7System.Types,System.Classes,Vcl.Graphics,Vcl.Controls,Vcl.Forms,8Vcl.Dialogs,Vcl.Menus,Vc......
  • delphi Image32 图像采样
    图像数据采样  代码:1unituFrmImageResampling;23interface45uses6Winapi.Windows,Winapi.Messages,Winapi.ShellAPI,//7System.SysUtils,System.Variants,System.Classes,Vcl.Graphics,Vcl.Controls,8Vcl.Forms,Vcl.Dialo......
  • Delphi 生成随机验证码
    Delphi生成随机验证码functionCodeImg(img:Timage):string; var  I,j,k: Integer;  vPoint: TPoint;  vLeft: Integer;  arrStr:array[1..36]ofstring;  strResult:string; begin  strResult:='';  arrStr[1]:=......
  • delphi:利用定时器读取串口返回数据
    定时器20毫秒运行一次,单字符读取,如果读取到就保存到全局变量receData中,否则就输出到文本框中,并重置receData。优点:单字符读取,解决了按长度读取的弊端,如果按长度读取,很多时候并不知道究竟要读取多长,有的时候能读取完整,有的时候只读取了部分。procedureTfrmLC.tmrReceDataTimer(S......