解决TcxTreeList使用的几个问题
2013-06-25 12:52
489 查看
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
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
相关文章推荐
- 使用GDB调试RB-tree的几个问题
- 使用OE(OpenEmbedded)遇到的几个问题与解决[转]
- 转:asp.net在使用fckeditor 2.6版的几个问题的解决
- 使用Volley来写一个List列表(Valley可以解决很大一部分android请求server的问题)
- 使用Matrix-tree与它的行列式来解决生成树计数问题
- Linux下 android SDK安装及使用时出现的几个问题解决办法(我遇到的)
- 初次使用bantu16.04LTS时几个小问题的解决方法记录
- 使用GDB调试RB-tree的几个问题(更正)
- find和mv的结合使用解决 arg list too long的问题
- AspxTreeList 点击刷新问题官网解决方法
- 问题-Delphi 中使用TStringList后,报out of memory 的解决方法
- 使用libxml提示libxml/tree.h找不到的问题解决
- DevExpress TreeList 常见问题解决方法
- 解决SharePoint中自定义新增和编辑List的页面时"增加附件"工作栏不能使用的问题
- 在xp和Win7上使用Tomcat 6.0经常遇到的几个问题及其解决方法
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
- iphone 开发中使用zbar时遇到的几个典型问题解决方法。
- 使用libxml提示libxml/tree.h找不到的问题解决
- 使用密匙让putty(或ssh)自动登录Linux遇到几个问题的解决方法
- sql server 使用的几个问题解决 记下来