【问题标题】:Delphi Prism : Replacement for TreeView AddchildObject functionDelphi Prism:替换 TreeView AddchildObject 函数
【发布时间】:2011-09-01 16:08:46
【问题描述】:

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

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

【问题讨论】:

  • WinForms的MSDN文档非常全面。 WinForms 有很多教程。对于 Prism 来说并不多,但您只需要习惯阅读 C# 和编写 Pascal。阅读 C# 和编写 Pascal。还要标记它 delphi 否则你不会得到很多视图。
  • @David 我就是这么做的——主要是阅读 C# 文档并尝试将其应用于 pascal。如果它不起作用或不知道我在做什么,那么我会在网上或书籍中搜索答案。

标签: .net treeview replace delphi-prism addchild


【解决方案1】:

我相信这里的程序员同行可能无法回答这个问题,我觉得这对于任何从事 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.

这是问题的链接。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多