如何在运行时将节点添加到FireMonkey的TreeView [英] How to add nodes to FireMonkey's TreeView at runtime

查看:59
本文介绍了如何在运行时将节点添加到FireMonkey的TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到在线文档或Delphi XE2随附的演示中用于向 FMX.TreeView.TTreeView 控件。那么,如何在运行时添加,删除和遍历FireMonkey TreeView的节点?

I can't found any sample in the online documentation, or in the demos included with Delphi XE2, for adding nodes to a FMX.TreeView.TTreeView control at runtime. So, how can I add, remove, and traverse nodes of a FireMonkey TreeView at runtime?

推荐答案

我认为我们都在学习在这一点上...

I think we are all learning at this point...

但是从我看到的TTreeView使用的原理来看,任何控件都可以成为另一个控件的父对象。

But from what I have seen the TTreeView use the principle that any control can parent another control.

您需要做的就是设置 Parent 属性,以使该项目显示为儿童。 / p>

All you need to do is set the Parent Property to get the item to show up as a child.

var
  Item1 : TTreeViewItem;
  Item2 : TTreeViewItem;
begin
  Item1 := TTreeViewItem.Create(Self);
  Item1.Text := 'My First Node';
  Item1.Parent := TreeView1;

  Item2 := TTreeViewItem.Create(Self);
  Item2.Text := 'My Child Node';
  Item2.Parent := Item1;
end;

因此,您可以做以前从未做过的事情,例如在TreeView中放置任何控件。例如,此代码将向Item2使用的区域添加一个按钮,直到该Item2可见,该按钮才可见。

Because of this you can do things never possible before, such as placing any control in the TreeView. For example this code will add a button to the area used by Item2, and the button won't be visible until the Item2 is visible.

  Button := TButton.Create(self);
  Button.Text := 'A Button';
  Button.Position.X := 100;
  Button.Parent := Item2;

这篇关于如何在运行时将节点添加到FireMonkey的TreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆