解决TcxTreeList使用的几个问题

1、节点遍历

Items是按树型结构存放的,单纯遍历Items,只能得到第一层的节点,网上很多例子,都是用递归处理,其实是不必的,TcxTreeList包含了一个AbsoluteItems,保存了顺序结构的节点,可以如下遍历:

  for i := 0 to ATreeList.AbsoluteCount - 1 do
    showmessage(ATreeList.AbsoluteItems[i].Texts[0]);

  

2、为节点增加CheckBox

ATreeList.OptionsView.CheckGroups := True;  //使CheckBox有效

设置了该属性后,节点不会发生任何变化,可以使用遍历设置属性,例如:

  for i := 0 to ATreeList.AbsoluteCount - 1 do

    ATreeList.AbsoluteItems[i].CheckGroupType := ncgCheckGroup;  //多选或单选

这样处理的话,每次加载节点之后都需要执行这项操作,比较麻烦,可以直接修改源代码cxTL.pas,实现自动切换,修改如下:

为TcxCustomTreeList增加属性:

private

  FCheckGroupType:TcxTreeListNodeCheckGroupType;

public

  property CheckGroupType: TcxTreeListNodeCheckGroupType read FCheckGroupType write SetCheckGroupType; default ncgNone;

 

//修改创建方法

constructor TcxCustomTreeList.Create(AOwner: TComponent);
begin
  ...原代码...

  FCheckGroupType := ncgNone;
end;

 

//设置CheckGroupType时,修改节点状态

procedure TcxCustomTreeList.SetCheckGroupType(
  const Value: TcxTreeListNodeCheckGroupType);
var
  i: Integer;
begin
  if FCheckGroupType <> Value then begin
    FCheckGroupType := Value;
    BeginUpdate;
    try
      FRoot.CheckGroupType := Value;
      for i := 0 to AbsoluteCount - 1 do
        AbsoluteItems[i].CheckGroupType := Value;
    finally
      EndUpdate;
    end;
  end;
end;

 

 

修改节点创建事件:

constructor TcxTreeListNode.Create(AOwner: TcxCustomTreeList);
begin
  ...原代码...

 

  //创建时设默认属性,忽略OptionsView.CheckGroups的值,无影响

  if (AOwner <> nil) then 

    CheckGroupType := AOwner.CheckGroupType;
end;

    

3、遍历选中的节点

   for i := 0 to AbsoluteCount - 1 do
     if AbsoluteItems[i].Checked then showmessage(AbsoluteItems[i].Texts[0]);

   

4、几个属性

TopNode:顶节点,实际上是第一个有效的节点

Root:第一层节点数组

Items:节点的子节点数组(如果是TreeList.Items相当于Root)

Texts,Values:值数组,对应Bands的Index

    

  

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
================================== ==注意:一共2个压缩包,这是第1个== ================================== *提示:无自动安装程序,包含所有源码、例子、帮助,请按照安装顺序安装!!! New Features in 13.1.4 (VCL Product Line) Breaking Changes To learn about breaking changes in this version, please refer to the following page: Breaking Changes in 13.1.4 (VCL Product Line) Known Issues To learn about known issues in this version, please refer to the following page: Known Issues in 13.1.4 (VCL Product Line) The following sections list all minor and major changes in DevExpress VCL 13.1.4. Note that products, controls and libraries which aren't mentioned in the list below are included in the unified installer for compatibility, but have not been updated. Enhancements and Updates New Features/Updates VCL Subscription ExpressTile Control ExpressDataController Resolved Issues ExpressBars Suite ExpressLayout Control ExpressNavBar ExpressPageControl ExpressPivotGrid Suite ExpressPrinting System ExpressQuantumGrid Suite ExpressQuantumTreeList Suite ExpressScheduler Suite ExpressSkins Library ExpressSpreadSheet ExpressTile Control ExpressVerticalGrid Suite ExpressDataController ExpressEditors Library ExpressLibrary Installation (VCL) New Features/Updates VCL Subscription S170932 - Documentation - Describe that the ExpressLayout Control and ExpressDocking Library are incompatible ExpressTile Control S172299 - Center the Back button and title text vertically within the title Common Libraries ExpressDataController S172107 - Add the capability to disable multi-threaded operations at the level of custom data sources (TcxCustomDataSource descendants) Resolved Issues ExpressBars Suite Q476901 - Documentation - The "Ribbon Application Menu" topic does not contain the menu creation steps that are specific to TdxRibbonBackstageView Q452658 - Documentation - The TdxCustomRibbonGalleryItem.GalleryGroups property is not marked as deprecated and is used in topics instead of TdxCustomRibbonGalleryItem.GalleryCategories Q513198 -
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值