我正在将 win32 软件迁移到 .NET,目前正在使用 Delphi Prism 中的 TreeView 控件。到目前为止,我能够将父节点和子节点添加到 TreeView。但是,我想知道 Delphi Prism TreeView 是否可以替换 AddchildObject 函数。如果没有,你会怎么做?
网上关于这方面的信息似乎很少。
我正在将 win32 软件迁移到 .NET,目前正在使用 Delphi Prism 中的 TreeView 控件。到目前为止,我能够将父节点和子节点添加到 TreeView。但是,我想知道 Delphi Prism TreeView 是否可以替换 AddchildObject 函数。如果没有,你会怎么做?
网上关于这方面的信息似乎很少。
我相信这个问题可能不会被这里的程序员同行回答,我觉得这对于任何做 Delphi Prism 的程序员来说都是一个重要的问题。所以,我决定自己回答这个问题而不是删除它,因为我在另一个 StackOverflow 问题中找到了答案。但是,我的问题和他们的问题不同,但需要相同的答案。
我编写了一个快速简单的 delphi prism 示例来展示如何使用树视图以及如何在树视图节点中存储和检索对象。
这是我的树视图示例
namespace TreeViewExample;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Windows.Forms,
System.ComponentModel;
type
/// <summary>
/// Summary description for MainForm.
/// </summary>
MainForm = partial class(System.Windows.Forms.Form)
private
method MainForm_Load(sender: System.Object; e: System.EventArgs);
method treeView1_Click(sender: System.Object; e: System.EventArgs);
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
theclass = class
thestr:String;
public
constructor;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
constructor theclass;
begin
thestr:='Testing Treeview.';
end;
method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
var topnode:treenode;
theObject:theclass;
begin
theObject:=new theclass;
treeview1.BeginUpdate;
topnode:=treeview1.Nodes.Add('node1');
topnode.Nodes.Add('no data node');
topnode.Nodes.Add('data node').Tag := theObject;
topnode.Expand;
treeview1.EndUpdate;
end;
method MainForm.treeView1_Click(sender: System.Object; e: System.EventArgs);
begin
if treeview1.SelectedNode.Text='data node' then
MessageBox.Show(theClass(Treeview1.SelectedNode.Tag).thestr);
end;
end.
这是问题的链接。