Delphi Prism:替换 TreeView AddchildObject 函数

发布于 2024-12-02 09:33:14 字数 185 浏览 0 评论 0原文

我正在将 win32 软件迁移到 .NET,目前正在使用 Delphi Prism 中的 TreeView 控件。到目前为止,我可以向 TreeView 添加父节点和子节点。但是,我想知道 Delphi Prism TreeView 是否有 AddchildObject 函数的替代品。如果没有,你会怎么做?

网上关于这方面的信息似乎很少。

I am in the process of migrating software for win32 to .NET and currently working with TreeView control in Delphi Prism. So far I am able to add parent nodes and child nodes to the TreeView. However, I would like to know if there is replacement for AddchildObject function for Delphi Prism TreeView. If not, how would you do it?

It seems there is very little information online about this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荭秂 2024-12-09 09:33:14

我相信这个问题在这里的程序员朋友们可能无法回答,我觉得这对于任何使用Delphi Prism的程序员来说都是一个重要的问题。因此,我决定自己回答这个问题,而不是删除它,因为我在另一个 StackOverflow 问题中找到了答案。然而,我的问题和他们的问题不同,但需要相同的答案。

我编写了一个快速简单的 delphi prism 示例,以展示如何使用树视图以及如何在树视图节点中存储和检索对象。

这是我的 Treeview 示例

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.

这是问题的链接。

在 C# 中使用树视图时将文本字段保存到数组(并从数组中提取数据)

I believe that this question may not get answered by the fellow programmers in here and I feel that this is an important question for any programmers doing Delphi Prism. So, I decided to answer the question myself instead of deleting it, since I found the answer for it in another StackOverflow question. However, my question and their question is different but require the same answer.

I wrote a quick and simple delphi prism sample to show how to use treeview and to be able to store and retrieve objects in the treeview node.

Here is my Treeview example

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.

Here is the link to the question.

save text fields to an Array (and pull data from the Array) when using treeview in c#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文