2011-09-01 64 views
0

我正在將win32的軟件遷移到.NET,目前正在使用Delphi Prism中的TreeView控件。到目前爲止,我能夠將父節點和子節點添加到TreeView。但是,我想知道是否有替代Delphi Prism TreeView的AddchildObject函數。如果不是,你會怎麼做?Delphi Prism:替換TreeView AddchildObject函數

看來關於這方面的信息很少。

+0

WinForms的MSDN文檔非常全面。有許多WinForms教程。對於Prism來說並不多,但你只需要習慣於閱讀C#和編寫Pascal。閱讀C#並編寫Pascal。也標記它delphi,否則你不會看到很多意見。 –

+0

@David我這樣做 - 大多閱讀C#文檔,並嘗試將其應用於pascal。如果它不起作用或不知道我在做什麼,那麼我會在網上或書籍上尋找答案。 – ThN

回答

1

我相信這個問題可能沒有得到這裏的同行程序員的回答,我覺得這對任何使用Delphi Prism的程序員來說都是一個重要的問題。所以,我決定自己回答這個問題,而不是刪除它,因爲我在另一個StackOverflow問題中找到了答案。但是,我的問題和他們的問題是不同的,但需要相同的答案。

我寫了一個快速簡單的delphi prism示例來演示如何使用treeview並能夠在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#