dev树状控件DBTreeList 添加复选框CheckBox

通过递归方法实现对DbTreeList 添加复选框实现

  • cxDbTreeList 控件功能强大,使用方便,Devexpress 为cxTreeList 控件设计可以自动级联选择的复选框,但从cxTreeList继承而来的cxDbTreeList 控件却未提供这一功能。(实际上是默认属性没有设置为复选框功能),下面通过递归方法来完成这一功能的实现
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxCustomData, cxStyles, cxTL, cxTLdxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, DB, cxTLData, cxDBTL, MemDS, DBAccess, Ora,
  StdCtrls, cxInplaceContainer, cxMaskEdit, Grids, DBGrids, cxCheckBox,
  cxTextEdit;

type
  TForm1 = class(TForm)
    cxTreeList1: TcxTreeList;
    Button1: TButton;
    OraSession1: TOraSession;
    OraQuery1: TOraQuery;
    cxDBTreeList1: TcxDBTreeList;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    OraQuery1ID: TFloatField;
    OraQuery1NAME: TStringField;
    OraQuery1PARENT: TFloatField;
    cxDBTreeList1cxDBTreeListColumn1: TcxDBTreeListColumn;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    cxDBTreeList1cxDBTreeListColumn3: TcxDBTreeListColumn;
    OraQueryIsCheck: TBooleanField;
    cxTreeList1Column1: TcxTreeListColumn;
    cxTreeList1Column2: TcxTreeListColumn;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
//通过该过程遍历设置节点Node的CheckGroupType属性为ncgCheckGroup
procedure CheckedSubNodes(ANode:TcxTreeListNode);
var
  i:integer;
begin
  for i:=0 to ANode.Count-1 do
  begin
    ANode.CheckGroupType:=ncgCheckGroup;
    if ANode.HasChildren then
    begin
      CheckedSubNodes(ANode.Items[i]);  //递归修改复选框分组类型
    end;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  cxDBTreeList1.OptionsView.CheckGroups:=True;//设置cxDbTreeList1 控件的视图显示方式为“可复选”模式
  CheckedSubNodes(cxDBTreeList1.Root);//遍历节点,设置节点属性
end;

end.

效果:
image

posted @ 2023-06-29 10:12  丹心石  阅读(457)  评论(0编辑  收藏  举报