TreeNode コンストラクタ ()
アセンブリ: System.Web (system.web.dll 内)


既定値を使用して TreeNode クラスの新しいインスタンスを初期化するには、このコンストラクタを使用します。
![]() |
---|
このコンストラクタを使用すると、TreeNode オブジェクトのすべてのプロパティが既定値に設定されます。オブジェクトの作成後に必要に応じてプロパティを設定してください。 |

このコンストラクタを使用して、TreeView コントロールにノードを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Add the first tree to the TreeView control. CreateTree("Section 1") ' Add the second tree to the TreeView control. CreateTree("Section 2") End If End Sub Sub CreateTree(ByVal NodeText As String) ' Create the root node using the default constructor. Dim root As TreeNode = New TreeNode root.Text = NodeText ' Use the ChildNodes property of the root TreeNode to add child nodes. ' Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(New TreeNode("Topic 1")) ' Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2")) ' Create the node using the constructor that takes the text, value, ' and imageUrl parameters. root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg")) ' Create the node using the constructor that takes the text, value, ' imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")) ' Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root) End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Init(Object sender, EventArgs e) { if(!IsPostBack) { // Add the first tree to the TreeView control. CreateTree("Section 1"); // Add the second tree to the TreeView control. CreateTree("Section 2"); } } void CreateTree(String NodeText) { // Create the root node using the default constructor. TreeNode root = new TreeNode(); root.Text = NodeText; // Use the ChildNodes property of the root TreeNode to add child nodes. // Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(new TreeNode("Topic 1")); // Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2")); // Create the node using the constructor that takes the text, value, // and imageUrl parameters. root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg")); // Create the node using the constructor that takes the text, value, // imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")); // Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root); } </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ ()
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


子ツリー ノードの割り当て先とするルート ツリー ノードを作成するコード例を次に示します。ArrayList の各 Customer オブジェクトの子ツリー ノードは、ルート ツリー ノードと、Customer オブジェクトに割り当てられている各 Order オブジェクトの子ツリー ノードに追加されます。Customer オブジェクトは Tag プロパティに割り当てられ、Customer オブジェクトを表すツリー ノードは Orange テキストで表示されます。この例は、Customer オブジェクトと Order オブジェクトが定義されていて、TreeView コントロールが Form に配置されていて、Customer オブジェクトを含む customerArray という名前の ArrayList があることを前提にしています。
Public Sub AddRootNodes() ' Add a root node to assign the customer nodes to. Dim rootNode As TreeNode rootNode = New TreeNode() rootNode.Text = "CustomerList" ' Add a main root treenode. myTreeView.Nodes.Add(rootNode) ' Add a root treenode for each Customer object in the ArrayList. Dim myCustomer As Customer For Each myCustomer In customerArray ' Add a child treenode for each Order object. Dim i As Integer = 0 Dim myTreeNodeArray(4) As TreeNode Dim myOrder As Order For Each myOrder In myCustomer.CustomerOrders myTreeNodeArray(i) = New TreeNode(myOrder.OrderID) i += 1 Next myOrder Dim customerNode As New TreeNode(myCustomer.CustomerName, _ myTreeNodeArray) ' Display the customer names with and Orange font. customerNode.ForeColor = Color.Orange ' Store the Customer object in the Tag property of the TreeNode. customerNode.Tag = myCustomer myTreeView.Nodes(0).Nodes.Add(customerNode) Next myCustomer End Sub
public void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode rootNode = new TreeNode(); rootNode.Text = "CustomerList"; // Add a main root treenode. myTreeView.Nodes.Add(rootNode); // Add a root treenode for each 'Customer' object in the ArrayList. foreach(Customer myCustomer in customerArray) { // Add a child treenode for each Order object. int i = 0; TreeNode[] myTreeNodeArray = new TreeNode[5]; foreach(Order myOrder in myCustomer.CustomerOrders) { myTreeNodeArray[i] = new TreeNode(myOrder.OrderID); i++; } TreeNode customerNode = new TreeNode(myCustomer.CustomerName , myTreeNodeArray); // Display the customer names with and Orange font. customerNode.ForeColor = Color.Orange; // Store the Customer object in the Tag property of the TreeNode. customerNode.Tag = myCustomer; myTreeView.Nodes[0].Nodes.Add(customerNode); } }
void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode^ rootNode = gcnew TreeNode; rootNode->Text = "CustomerList"; // Add a main root treenode. myTreeView->Nodes->Add( rootNode ); // Add a root treenode for each 'Customer' object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current); // Add a child treenode for each Order object. int i = 0; array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(5); IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ myOrder = safe_cast<Order^>(myEnum->Current); myTreeNodeArray[ i ] = gcnew TreeNode( myOrder->OrderID ); i++; } TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,myTreeNodeArray ); // Display the customer names with and Orange font. customerNode->ForeColor = Color::Orange; // Store the Customer Object* in the Tag property of the TreeNode. customerNode->Tag = myCustomer; myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode ); } }
public void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode rootNode = new TreeNode(); rootNode.set_Text("CustomerList"); // Add a main root treenode. myTreeView.get_Nodes().Add(rootNode); // Add a root treenode for each 'Customer' object in the ArrayList. for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) { Customer myCustomer = (Customer)customerArray.get_Item(iCtr1); // Add a child treenode for each Order object. int i = 0; TreeNode myTreeNodeArray[] = new TreeNode[5]; for (int iCtr2 = 0; iCtr2 < myCustomer.customerOrders.get_Count(); iCtr2++) { Order myOrder = (Order)myCustomer.customerOrders.get_Item(iCtr2); myTreeNodeArray.set_Item(i, new TreeNode(myOrder.orderID)); i++; } TreeNode customerNode = new TreeNode(myCustomer.customerName, myTreeNodeArray); // Display the customer names with and Orange font. customerNode.set_ForeColor(Color.get_Orange()); // Store the Customer object in the Tag property of the TreeNode. customerNode.set_Tag(myCustomer); myTreeView.get_Nodes().get_Item(0).get_Nodes().Add(customerNode); } } //AddRootNodes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, String)
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、text パラメータで指定されたテキストおよび value パラメータで指定された値で TreeNode クラスの新しいインスタンスを初期化します。
TreeNode のインスタンスの初期プロパティ値を次の表に示します。

このコンストラクタを使用して、TreeView コントロールにノードを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Add the first tree to the TreeView control. CreateTree("Section 1") ' Add the second tree to the TreeView control. CreateTree("Section 2") End If End Sub Sub CreateTree(ByVal NodeText As String) ' Create the root node using the default constructor. Dim root As TreeNode = New TreeNode root.Text = NodeText ' Use the ChildNodes property of the root TreeNode to add child nodes. ' Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(New TreeNode("Topic 1")) ' Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2")) ' Create the node using the constructor that takes the text, value, ' and imageUrl parameters. root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg")) ' Create the node using the constructor that takes the text, value, ' imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")) ' Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root) End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Init(Object sender, EventArgs e) { if(!IsPostBack) { // Add the first tree to the TreeView control. CreateTree("Section 1"); // Add the second tree to the TreeView control. CreateTree("Section 2"); } } void CreateTree(String NodeText) { // Create the root node using the default constructor. TreeNode root = new TreeNode(); root.Text = NodeText; // Use the ChildNodes property of the root TreeNode to add child nodes. // Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(new TreeNode("Topic 1")); // Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2")); // Create the node using the constructor that takes the text, value, // and imageUrl parameters. root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg")); // Create the node using the constructor that takes the text, value, // imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")); // Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root); } </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ

名前 | 説明 |
---|---|
TreeNode () | TreeNode クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
TreeNode (String) | ラベル テキストを指定して、TreeNode クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
TreeNode (SerializationInfo, StreamingContext) | シリアル化情報とコンテキストを指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, TreeNode[]) | 指定したラベル テキストと子ツリー ノードを使用して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, Int32, Int32) | ラベル テキストと、ツリー ノードが選択されているときと選択されていないときに表示するイメージをそれぞれ指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, Int32, Int32, TreeNode[]) | ラベル テキスト、子ツリー ノード、およびツリー ノードが選択されているときと選択されていないときに表示するイメージをそれぞれ指定して、TreeNode クラスの新しいインスタンスを初期化します。 |

TreeNode コンストラクタ (SerializationInfo, StreamingContext)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim serializationInfo As SerializationInfo Dim context As StreamingContext Dim instance As New TreeNode(serializationInfo, context)

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)



TreeView コントロールに顧客情報を表示するコード例を次に示します。ルート ツリー ノードに顧客名が表示され、各顧客に割り当てられた発注番号が子ツリー ノードに表示されます。この例では、1,000 人の顧客が表示され、顧客ごとに 15 の発注内容が示されます。BeginUpdate メソッドと EndUpdate メソッドを使用すると、TreeView は再描画されません。TreeView が TreeNode オブジェクトを作成して描画する間、待機 Cursor が表示されます。この例では、Order オブジェクトのコレクションを保持できる Customer オブジェクトが存在する必要があります。また、TreeView コントロールのインスタンスが Form 上に作成されている必要もあります。
' Create a new ArrayList to hold the Customer objects. Private customerArray As New ArrayList() Private Sub FillMyTreeView() ' Add customers to the ArrayList of Customer objects. Dim x As Integer For x = 0 To 999 customerArray.Add(New Customer("Customer" + x.ToString())) Next x ' Add orders to each Customer object in the ArrayList. Dim customer1 As Customer For Each customer1 In customerArray Dim y As Integer For y = 0 To 14 customer1.CustomerOrders.Add(New Order("Order" + y.ToString())) Next y Next customer1 ' Display a wait cursor while the TreeNodes are being created. Cursor.Current = New Cursor("MyWait.cur") ' Suppress repainting the TreeView until all the objects have been created. treeView1.BeginUpdate() ' Clear the TreeView each time the method is called. treeView1.Nodes.Clear() ' Add a root TreeNode for each Customer object in the ArrayList. Dim customer2 As Customer For Each customer2 In customerArray treeView1.Nodes.Add(New TreeNode(customer2.CustomerName)) ' Add a child TreeNode for each Order object in the current Customer object. Dim order1 As Order For Each order1 In customer2.CustomerOrders treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _ New TreeNode(customer2.CustomerName + "." + order1.OrderID)) Next order1 Next customer2 ' Reset the cursor to the default for all controls. Cursor.Current = System.Windows.Forms.Cursors.Default ' Begin repainting the TreeView. treeView1.EndUpdate() End Sub 'FillMyTreeView
// Create a new ArrayList to hold the Customer objects. private ArrayList customerArray = new ArrayList(); private void FillMyTreeView() { // Add customers to the ArrayList of Customer objects. for(int x=0; x<1000; x++) { customerArray.Add(new Customer("Customer" + x.ToString())); } // Add orders to each Customer object in the ArrayList. foreach(Customer customer1 in customerArray) { for(int y=0; y<15; y++) { customer1.CustomerOrders.Add(new Order("Order" + y.ToString())); } } // Display a wait cursor while the TreeNodes are being created. Cursor.Current = new Cursor("MyWait.cur"); // Suppress repainting the TreeView until all the objects have been created. treeView1.BeginUpdate(); // Clear the TreeView each time the method is called. treeView1.Nodes.Clear(); // Add a root TreeNode for each Customer object in the ArrayList. foreach(Customer customer2 in customerArray) { treeView1.Nodes.Add(new TreeNode(customer2.CustomerName)); // Add a child treenode for each Order object in the current Customer object. foreach(Order order1 in customer2.CustomerOrders) { treeView1.Nodes[customerArray.IndexOf(customer2)].Nodes.Add( new TreeNode(customer2.CustomerName + "." + order1.OrderID)); } } // Reset the cursor to the default for all controls. Cursor.Current = Cursors.Default; // Begin repainting the TreeView. treeView1.EndUpdate(); }
void FillMyTreeView() { // Add customers to the ArrayList of Customer objects. for ( int x = 0; x < 1000; x++ ) { customerArray->Add( gcnew Customer( "Customer " + x ) ); } // Add orders to each Customer object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ customer1 = safe_cast<Customer^>(myEnum->Current); for ( int y = 0; y < 15; y++ ) { customer1->CustomerOrders->Add( gcnew Order( "Order " + y ) ); } } // Display a wait cursor while the TreeNodes are being created. ::Cursor::Current = gcnew System::Windows::Forms::Cursor( "MyWait.cur" ); // Suppress repainting the TreeView until all the objects have been created. treeView1->BeginUpdate(); // Clear the TreeView each time the method is called. treeView1->Nodes->Clear(); // Add a root TreeNode for each Customer object in the ArrayList. while ( myEnum->MoveNext() ) { Customer^ customer2 = safe_cast<Customer^>(myEnum->Current); treeView1->Nodes->Add( gcnew TreeNode( customer2->CustomerName ) ); // Add a child treenode for each Order object in the current Customer object. IEnumerator^ myEnum = customer2->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ order1 = safe_cast<Order^>(myEnum->Current); treeView1->Nodes[ customerArray->IndexOf( customer2 ) ]->Nodes->Add( gcnew TreeNode( customer2->CustomerName + "." + order1->OrderID ) ); } } // Reset the cursor to the default for all controls. ::Cursor::Current = Cursors::Default; // Begin repainting the TreeView. treeView1->EndUpdate(); }
// Create a new ArrayList to hold the Customer objects. private ArrayList customerArray = new ArrayList(); private void FillMyTreeView() { // Add customers to the ArrayList of Customer objects. for (int x = 0; x < 1000; x++) { customerArray.Add(new Customer("Customer" + ((Int32)x).ToString())); } // Add orders to each Customer object in the ArrayList. for (int iCtr = 0; iCtr < customerArray.get_Count(); iCtr++) { Customer customer1 = (Customer)customerArray.get_Item(iCtr); for (int y = 0; y < 15; y++) { customer1.get_CustomerOrders().Add(new Order("Order" + ((Int32)y).ToString())); } } // Display a wait cursor while the TreeNodes are being created. get_Cursor().set_Current(new Cursor("MyWait.cur")); // Suppress repainting the TreeView until all the objects have // been created. treeView1.BeginUpdate(); // Clear the TreeView each time the method is called. treeView1.get_Nodes().Clear(); // Add a root TreeNode for each Customer object in the ArrayList. for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) { Customer customer2 = (Customer)customerArray.get_Item(iCtr1); treeView1.get_Nodes().Add(new TreeNode(customer2.get_CustomerName())); // Add a child treenode for each Order object in the current // Customer object. for (int iCtr2 = 0; iCtr2 < customer2.get_CustomerOrders(). get_Count(); iCtr2++) { Order order1 = (Order)customer2.get_CustomerOrders(). get_Item(iCtr2); treeView1.get_Nodes(). get_Item(customerArray.IndexOf(customer2)).get_Nodes(). Add(new TreeNode(customer2.get_CustomerName() + "." + order1.get_OrderID())); } } // Reset the cursor to the default for all controls. get_Cursor().set_Current(Cursors.get_Default()); // Begin repainting the TreeView. treeView1.EndUpdate(); } //FillMyTreeView

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, Int32, Int32, TreeNode[])
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public Sub New ( _ text As String, _ imageIndex As Integer, _ selectedImageIndex As Integer, _ children As TreeNode() _ )
Dim text As String Dim imageIndex As Integer Dim selectedImageIndex As Integer Dim children As TreeNode() Dim instance As New TreeNode(text, imageIndex, selectedImageIndex, children)
public: TreeNode ( String^ text, int imageIndex, int selectedImageIndex, array<TreeNode^>^ children )
public function TreeNode ( text : String, imageIndex : int, selectedImageIndex : int, children : TreeNode[] )

text パラメータの値はノードの Text プロパティに代入され、ツリー ノードのラベルになります。imageIndex 値と selectedImageIndex 値は、TreeView.ImageList プロパティに割り当てられた ImageList に格納されている Image のインデックス値です。imageIndex パラメータで参照されるイメージは、ツリー ノードが選択されていないときに表示されます。同様に、selectedImageIndex パラメータで参照されるイメージは、ツリー ノードが選択されているときに表示されます。children 配列に格納されているツリー ノードは、Nodes プロパティに格納される TreeNodeCollection に追加されます。

ImageList を作成して TreeView コントロールに割り当て、TreeView コントロールに TreeNode オブジェクトを設定するコード例を次に示します。ツリー ノードには、選択状態または非選択状態のときに表示される、ImageList からのイメージが割り当てられます。この例は、TreeView が配置された Form があり、それぞれが Order オブジェクトを格納している Customer オブジェクトが配置された ArrayList があることを前提にしています。また、Customer オブジェクトと Order オブジェクトが定義されている必要があります。
Private Sub FillTreeView() ' Load the images in an ImageList. Dim myImageList As New ImageList() myImageList.Images.Add(Image.FromFile("Default.gif")) myImageList.Images.Add(Image.FromFile("SelectedDefault.gif")) myImageList.Images.Add(Image.FromFile("Root.gif")) myImageList.Images.Add(Image.FromFile("UnselectedCustomer.gif")) myImageList.Images.Add(Image.FromFile("SelectedCustomer.gif")) myImageList.Images.Add(Image.FromFile("UnselectedOrder.gif")) myImageList.Images.Add(Image.FromFile("SelectedOrder.gif")) ' Assign the ImageList to the TreeView. myTreeView.ImageList = myImageList ' Set the TreeView control's default image and selected image indexes. myTreeView.ImageIndex = 0 myTreeView.SelectedImageIndex = 1 ' Set the index of image from the ' ImageList for selected and unselected tree nodes. Me.rootImageIndex = 2 Me.selectedCustomerImageIndex = 3 Me.unselectedCustomerImageIndex = 4 Me.selectedOrderImageIndex = 5 Me.unselectedOrderImageIndex = 6 ' Create the root tree node. Dim rootNode As New TreeNode("CustomerList") rootNode.ImageIndex = rootImageIndex rootNode.SelectedImageIndex = rootImageIndex ' Add a main root tree node. myTreeView.Nodes.Add(rootNode) ' Add a root tree node for each Customer object in the ArrayList. Dim myCustomer As Customer For Each myCustomer In customerArray ' Add a child tree node for each Order object. Dim countIndex As Integer = 0 Dim myTreeNodeArray(myCustomer.CustomerOrders.Count) As TreeNode Dim myOrder As Order For Each myOrder In myCustomer.CustomerOrders ' Add the Order tree node to the array. myTreeNodeArray(countIndex) = New TreeNode(myOrder.OrderID, _ unselectedOrderImageIndex, selectedOrderImageIndex) countIndex += 1 Next myOrder ' Add the Customer tree node. Dim customerNode As New TreeNode(myCustomer.CustomerName, _ unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray) myTreeView.Nodes(0).Nodes.Add(customerNode) Next myCustomer End Sub
private void FillTreeView() { // Load the images in an ImageList. ImageList myImageList = new ImageList(); myImageList.Images.Add(Image.FromFile("Default.gif")); myImageList.Images.Add(Image.FromFile("SelectedDefault.gif")); myImageList.Images.Add(Image.FromFile("Root.gif")); myImageList.Images.Add(Image.FromFile("UnselectedCustomer.gif")); myImageList.Images.Add(Image.FromFile("SelectedCustomer.gif")); myImageList.Images.Add(Image.FromFile("UnselectedOrder.gif")); myImageList.Images.Add(Image.FromFile("SelectedOrder.gif")); // Assign the ImageList to the TreeView. myTreeView.ImageList = myImageList; // Set the TreeView control's default image and selected image indexes. myTreeView.ImageIndex = 0; myTreeView.SelectedImageIndex = 1; /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this.rootImageIndex = 2; this.selectedCustomerImageIndex = 3; this.unselectedCustomerImageIndex = 4; this.selectedOrderImageIndex = 5; this.unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode rootNode = new TreeNode("CustomerList"); rootNode.ImageIndex = rootImageIndex; rootNode.SelectedImageIndex = rootImageIndex; // Add a main root tree node. myTreeView.Nodes.Add(rootNode); // Add a root tree node for each Customer object in the ArrayList. foreach(Customer myCustomer in customerArray) { // Add a child tree node for each Order object. int countIndex=0; TreeNode[] myTreeNodeArray = new TreeNode[myCustomer.CustomerOrders.Count]; foreach(Order myOrder in myCustomer.CustomerOrders) { // Add the Order tree node to the array. myTreeNodeArray[countIndex] = new TreeNode(myOrder.OrderID , unselectedOrderImageIndex, selectedOrderImageIndex); countIndex++; } // Add the Customer tree node. TreeNode customerNode = new TreeNode(myCustomer.CustomerName , unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray); myTreeView.Nodes[0].Nodes.Add(customerNode); } }
void FillTreeView() { // Load the images in an ImageList. ImageList^ myImageList = gcnew ImageList; myImageList->Images->Add( Image::FromFile( "Default.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedDefault.gif" ) ); myImageList->Images->Add( Image::FromFile( "Root.gif" ) ); myImageList->Images->Add( Image::FromFile( "UnselectedCustomer.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedCustomer.gif" ) ); myImageList->Images->Add( Image::FromFile( "UnselectedOrder.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedOrder.gif" ) ); // Assign the ImageList to the TreeView. myTreeView->ImageList = myImageList; // Set the TreeView control's default image and selected image indexes. myTreeView->ImageIndex = 0; myTreeView->SelectedImageIndex = 1; /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this->rootImageIndex = 2; this->selectedCustomerImageIndex = 3; this->unselectedCustomerImageIndex = 4; this->selectedOrderImageIndex = 5; this->unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode^ rootNode = gcnew TreeNode( "CustomerList" ); rootNode->ImageIndex = rootImageIndex; rootNode->SelectedImageIndex = rootImageIndex; // Add a main root tree node. myTreeView->Nodes->Add( rootNode ); // Add a root tree node for each Customer object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current); // Add a child tree node for each Order object. int countIndex = 0; array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(myCustomer->CustomerOrders->Count); IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ myOrder = safe_cast<Order^>(myEnum->Current); // Add the Order tree node to the array. myTreeNodeArray[ countIndex ] = gcnew TreeNode( myOrder->OrderID,unselectedOrderImageIndex,selectedOrderImageIndex ); countIndex++; } TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,unselectedCustomerImageIndex,selectedCustomerImageIndex,myTreeNodeArray ); myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode ); } }
private void FillTreeView() { // Load the images in an ImageList. ImageList myImageList = new ImageList(); myImageList.get_Images().Add(Image.FromFile("Default.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedDefault.gif")); myImageList.get_Images().Add(Image.FromFile("Root.gif")); myImageList.get_Images().Add(Image.FromFile("UnselectedCustomer.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedCustomer.gif")); myImageList.get_Images().Add(Image.FromFile("UnselectedOrder.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedOrder.gif")); // Assign the ImageList to the TreeView. myTreeView.set_ImageList(myImageList); // Set the TreeView control's default image and selected image indexes. myTreeView.set_ImageIndex(0); myTreeView.set_SelectedImageIndex(1); /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this.rootImageIndex = 2; this.selectedCustomerImageIndex = 3; this.unselectedCustomerImageIndex = 4; this.selectedOrderImageIndex = 5; this.unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode rootNode = new TreeNode("CustomerList"); rootNode.set_ImageIndex(rootImageIndex); rootNode.set_SelectedImageIndex(rootImageIndex); // Add a main root tree node. myTreeView.get_Nodes().Add(rootNode); // Add a root tree node for each Customer object in the ArrayList. for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) { Customer myCustomer = (Customer)customerArray.get_Item(iCtr1); // Add a child tree node for each Order object. int countIndex = 0; TreeNode myTreeNodeArray[] = new TreeNode[myCustomer.customerOrders.get_Count()]; for (int iCtr2 = 0; iCtr2 < myCustomer.customerOrders.get_Count(); iCtr2++) { Order myOrder = (Order)myCustomer.customerOrders.get_Item(iCtr2); // Add the Order tree node to the array. myTreeNodeArray.set_Item(countIndex, new TreeNode(myOrder.orderID, unselectedOrderImageIndex , selectedOrderImageIndex)); countIndex++; } // Add the Customer tree node. TreeNode customerNode = new TreeNode(myCustomer.customerName , unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray); myTreeView.get_Nodes().get_Item(0).get_Nodes().Add(customerNode); } } //FillTreeView

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, TreeNode[])
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


text パラメータの値はノードの Text プロパティに代入され、ツリー ノードのラベルになります。children 配列に格納されているツリー ノードは、Nodes プロパティに格納される TreeNodeCollection に追加されます。

子ツリー ノードの割り当て先とするルート ツリー ノードを作成するコード例を次に示します。ArrayList の各 Customer オブジェクトの子ツリー ノードは、ルート ツリー ノードと、Customer オブジェクトに割り当てられている各 Order オブジェクトの子ツリー ノードに追加されます。Customer オブジェクトは Tag プロパティに割り当てられ、Customer オブジェクトを表すツリー ノードは Orange テキストで表示されます。この例は、Customer オブジェクトと Order オブジェクトが定義されていて、TreeView コントロールが Form に配置されていて、Customer オブジェクトを含む customerArray という名前の ArrayList があることを前提にしています。
Public Sub AddRootNodes() ' Add a root node to assign the customer nodes to. Dim rootNode As TreeNode rootNode = New TreeNode() rootNode.Text = "CustomerList" ' Add a main root treenode. myTreeView.Nodes.Add(rootNode) ' Add a root treenode for each Customer object in the ArrayList. Dim myCustomer As Customer For Each myCustomer In customerArray ' Add a child treenode for each Order object. Dim i As Integer = 0 Dim myTreeNodeArray(4) As TreeNode Dim myOrder As Order For Each myOrder In myCustomer.CustomerOrders myTreeNodeArray(i) = New TreeNode(myOrder.OrderID) i += 1 Next myOrder Dim customerNode As New TreeNode(myCustomer.CustomerName, _ myTreeNodeArray) ' Display the customer names with and Orange font. customerNode.ForeColor = Color.Orange ' Store the Customer object in the Tag property of the TreeNode. customerNode.Tag = myCustomer myTreeView.Nodes(0).Nodes.Add(customerNode) Next myCustomer End Sub
public void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode rootNode = new TreeNode(); rootNode.Text = "CustomerList"; // Add a main root treenode. myTreeView.Nodes.Add(rootNode); // Add a root treenode for each 'Customer' object in the ArrayList. foreach(Customer myCustomer in customerArray) { // Add a child treenode for each Order object. int i = 0; TreeNode[] myTreeNodeArray = new TreeNode[5]; foreach(Order myOrder in myCustomer.CustomerOrders) { myTreeNodeArray[i] = new TreeNode(myOrder.OrderID); i++; } TreeNode customerNode = new TreeNode(myCustomer.CustomerName , myTreeNodeArray); // Display the customer names with and Orange font. customerNode.ForeColor = Color.Orange; // Store the Customer object in the Tag property of the TreeNode. customerNode.Tag = myCustomer; myTreeView.Nodes[0].Nodes.Add(customerNode); } }
void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode^ rootNode = gcnew TreeNode; rootNode->Text = "CustomerList"; // Add a main root treenode. myTreeView->Nodes->Add( rootNode ); // Add a root treenode for each 'Customer' object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current); // Add a child treenode for each Order object. int i = 0; array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(5); IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ myOrder = safe_cast<Order^>(myEnum->Current); myTreeNodeArray[ i ] = gcnew TreeNode( myOrder->OrderID ); i++; } TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,myTreeNodeArray ); // Display the customer names with and Orange font. customerNode->ForeColor = Color::Orange; // Store the Customer Object* in the Tag property of the TreeNode. customerNode->Tag = myCustomer; myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode ); } }
public void AddRootNodes() { // Add a root node to assign the customer nodes to. TreeNode rootNode = new TreeNode(); rootNode.set_Text("CustomerList"); // Add a main root treenode. myTreeView.get_Nodes().Add(rootNode); // Add a root treenode for each 'Customer' object in the ArrayList. for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) { Customer myCustomer = (Customer)customerArray.get_Item(iCtr1); // Add a child treenode for each Order object. int i = 0; TreeNode myTreeNodeArray[] = new TreeNode[5]; for (int iCtr2 = 0; iCtr2 < myCustomer.customerOrders.get_Count(); iCtr2++) { Order myOrder = (Order)myCustomer.customerOrders.get_Item(iCtr2); myTreeNodeArray.set_Item(i, new TreeNode(myOrder.orderID)); i++; } TreeNode customerNode = new TreeNode(myCustomer.customerName, myTreeNodeArray); // Display the customer names with and Orange font. customerNode.set_ForeColor(Color.get_Orange()); // Store the Customer object in the Tag property of the TreeNode. customerNode.set_Tag(myCustomer); myTreeView.get_Nodes().get_Item(0).get_Nodes().Add(customerNode); } } //AddRootNodes

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, Int32, Int32)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim text As String Dim imageIndex As Integer Dim selectedImageIndex As Integer Dim instance As New TreeNode(text, imageIndex, selectedImageIndex)

text パラメータの値はノードの Text プロパティに代入され、ツリー ノードのラベルになります。imageIndex 値と selectedImageIndex 値は、TreeView.ImageList プロパティに割り当てられた ImageList に格納されている Image のインデックス値です。imageIndex プロパティで参照されるイメージは、ツリー ノードが選択されていないときに表示されます。同様に、selectedImageIndex プロパティで参照されるイメージは、ツリー ノードが選択されているときに表示されます。

ImageList を作成して TreeView コントロールに割り当て、TreeView コントロールに TreeNode オブジェクトを設定するコード例を次に示します。ツリー ノードには、選択状態または非選択状態のときに表示される、ImageList からのイメージが割り当てられます。この例は、TreeView が配置された Form があり、それぞれが Order オブジェクトを格納している Customer オブジェクトが配置された ArrayList があることを前提にしています。また、Customer オブジェクトと Order オブジェクトが定義されている必要があります。
Private Sub FillTreeView() ' Load the images in an ImageList. Dim myImageList As New ImageList() myImageList.Images.Add(Image.FromFile("Default.gif")) myImageList.Images.Add(Image.FromFile("SelectedDefault.gif")) myImageList.Images.Add(Image.FromFile("Root.gif")) myImageList.Images.Add(Image.FromFile("UnselectedCustomer.gif")) myImageList.Images.Add(Image.FromFile("SelectedCustomer.gif")) myImageList.Images.Add(Image.FromFile("UnselectedOrder.gif")) myImageList.Images.Add(Image.FromFile("SelectedOrder.gif")) ' Assign the ImageList to the TreeView. myTreeView.ImageList = myImageList ' Set the TreeView control's default image and selected image indexes. myTreeView.ImageIndex = 0 myTreeView.SelectedImageIndex = 1 ' Set the index of image from the ' ImageList for selected and unselected tree nodes. Me.rootImageIndex = 2 Me.selectedCustomerImageIndex = 3 Me.unselectedCustomerImageIndex = 4 Me.selectedOrderImageIndex = 5 Me.unselectedOrderImageIndex = 6 ' Create the root tree node. Dim rootNode As New TreeNode("CustomerList") rootNode.ImageIndex = rootImageIndex rootNode.SelectedImageIndex = rootImageIndex ' Add a main root tree node. myTreeView.Nodes.Add(rootNode) ' Add a root tree node for each Customer object in the ArrayList. Dim myCustomer As Customer For Each myCustomer In customerArray ' Add a child tree node for each Order object. Dim countIndex As Integer = 0 Dim myTreeNodeArray(myCustomer.CustomerOrders.Count) As TreeNode Dim myOrder As Order For Each myOrder In myCustomer.CustomerOrders ' Add the Order tree node to the array. myTreeNodeArray(countIndex) = New TreeNode(myOrder.OrderID, _ unselectedOrderImageIndex, selectedOrderImageIndex) countIndex += 1 Next myOrder ' Add the Customer tree node. Dim customerNode As New TreeNode(myCustomer.CustomerName, _ unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray) myTreeView.Nodes(0).Nodes.Add(customerNode) Next myCustomer End Sub
private void FillTreeView() { // Load the images in an ImageList. ImageList myImageList = new ImageList(); myImageList.Images.Add(Image.FromFile("Default.gif")); myImageList.Images.Add(Image.FromFile("SelectedDefault.gif")); myImageList.Images.Add(Image.FromFile("Root.gif")); myImageList.Images.Add(Image.FromFile("UnselectedCustomer.gif")); myImageList.Images.Add(Image.FromFile("SelectedCustomer.gif")); myImageList.Images.Add(Image.FromFile("UnselectedOrder.gif")); myImageList.Images.Add(Image.FromFile("SelectedOrder.gif")); // Assign the ImageList to the TreeView. myTreeView.ImageList = myImageList; // Set the TreeView control's default image and selected image indexes. myTreeView.ImageIndex = 0; myTreeView.SelectedImageIndex = 1; /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this.rootImageIndex = 2; this.selectedCustomerImageIndex = 3; this.unselectedCustomerImageIndex = 4; this.selectedOrderImageIndex = 5; this.unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode rootNode = new TreeNode("CustomerList"); rootNode.ImageIndex = rootImageIndex; rootNode.SelectedImageIndex = rootImageIndex; // Add a main root tree node. myTreeView.Nodes.Add(rootNode); // Add a root tree node for each Customer object in the ArrayList. foreach(Customer myCustomer in customerArray) { // Add a child tree node for each Order object. int countIndex=0; TreeNode[] myTreeNodeArray = new TreeNode[myCustomer.CustomerOrders.Count]; foreach(Order myOrder in myCustomer.CustomerOrders) { // Add the Order tree node to the array. myTreeNodeArray[countIndex] = new TreeNode(myOrder.OrderID , unselectedOrderImageIndex, selectedOrderImageIndex); countIndex++; } // Add the Customer tree node. TreeNode customerNode = new TreeNode(myCustomer.CustomerName , unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray); myTreeView.Nodes[0].Nodes.Add(customerNode); } }
void FillTreeView() { // Load the images in an ImageList. ImageList^ myImageList = gcnew ImageList; myImageList->Images->Add( Image::FromFile( "Default.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedDefault.gif" ) ); myImageList->Images->Add( Image::FromFile( "Root.gif" ) ); myImageList->Images->Add( Image::FromFile( "UnselectedCustomer.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedCustomer.gif" ) ); myImageList->Images->Add( Image::FromFile( "UnselectedOrder.gif" ) ); myImageList->Images->Add( Image::FromFile( "SelectedOrder.gif" ) ); // Assign the ImageList to the TreeView. myTreeView->ImageList = myImageList; // Set the TreeView control's default image and selected image indexes. myTreeView->ImageIndex = 0; myTreeView->SelectedImageIndex = 1; /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this->rootImageIndex = 2; this->selectedCustomerImageIndex = 3; this->unselectedCustomerImageIndex = 4; this->selectedOrderImageIndex = 5; this->unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode^ rootNode = gcnew TreeNode( "CustomerList" ); rootNode->ImageIndex = rootImageIndex; rootNode->SelectedImageIndex = rootImageIndex; // Add a main root tree node. myTreeView->Nodes->Add( rootNode ); // Add a root tree node for each Customer object in the ArrayList. IEnumerator^ myEnum = customerArray->GetEnumerator(); while ( myEnum->MoveNext() ) { Customer^ myCustomer = safe_cast<Customer^>(myEnum->Current); // Add a child tree node for each Order object. int countIndex = 0; array<TreeNode^>^myTreeNodeArray = gcnew array<TreeNode^>(myCustomer->CustomerOrders->Count); IEnumerator^ myEnum = myCustomer->CustomerOrders->GetEnumerator(); while ( myEnum->MoveNext() ) { Order^ myOrder = safe_cast<Order^>(myEnum->Current); // Add the Order tree node to the array. myTreeNodeArray[ countIndex ] = gcnew TreeNode( myOrder->OrderID,unselectedOrderImageIndex,selectedOrderImageIndex ); countIndex++; } TreeNode^ customerNode = gcnew TreeNode( myCustomer->CustomerName,unselectedCustomerImageIndex,selectedCustomerImageIndex,myTreeNodeArray ); myTreeView->Nodes[ 0 ]->Nodes->Add( customerNode ); } }
private void FillTreeView() { // Load the images in an ImageList. ImageList myImageList = new ImageList(); myImageList.get_Images().Add(Image.FromFile("Default.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedDefault.gif")); myImageList.get_Images().Add(Image.FromFile("Root.gif")); myImageList.get_Images().Add(Image.FromFile("UnselectedCustomer.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedCustomer.gif")); myImageList.get_Images().Add(Image.FromFile("UnselectedOrder.gif")); myImageList.get_Images().Add(Image.FromFile("SelectedOrder.gif")); // Assign the ImageList to the TreeView. myTreeView.set_ImageList(myImageList); // Set the TreeView control's default image and selected image indexes. myTreeView.set_ImageIndex(0); myTreeView.set_SelectedImageIndex(1); /* Set the index of image from the ImageList for selected and unselected tree nodes.*/ this.rootImageIndex = 2; this.selectedCustomerImageIndex = 3; this.unselectedCustomerImageIndex = 4; this.selectedOrderImageIndex = 5; this.unselectedOrderImageIndex = 6; // Create the root tree node. TreeNode rootNode = new TreeNode("CustomerList"); rootNode.set_ImageIndex(rootImageIndex); rootNode.set_SelectedImageIndex(rootImageIndex); // Add a main root tree node. myTreeView.get_Nodes().Add(rootNode); // Add a root tree node for each Customer object in the ArrayList. for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) { Customer myCustomer = (Customer)customerArray.get_Item(iCtr1); // Add a child tree node for each Order object. int countIndex = 0; TreeNode myTreeNodeArray[] = new TreeNode[myCustomer.customerOrders.get_Count()]; for (int iCtr2 = 0; iCtr2 < myCustomer.customerOrders.get_Count(); iCtr2++) { Order myOrder = (Order)myCustomer.customerOrders.get_Item(iCtr2); // Add the Order tree node to the array. myTreeNodeArray.set_Item(countIndex, new TreeNode(myOrder.orderID, unselectedOrderImageIndex , selectedOrderImageIndex)); countIndex++; } // Add the Customer tree node. TreeNode customerNode = new TreeNode(myCustomer.customerName , unselectedCustomerImageIndex, selectedCustomerImageIndex, myTreeNodeArray); myTreeView.get_Nodes().get_Item(0).get_Nodes().Add(customerNode); } } //FillTreeView

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String)
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、text パラメータで指定されたテキストで TreeNode クラスの新しいインスタンスを初期化します。
TreeNode のインスタンスの初期プロパティ値を次の表に示します。

このコンストラクタを使用して、TreeView コントロールにノードを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Add the first tree to the TreeView control. CreateTree("Section 1") ' Add the second tree to the TreeView control. CreateTree("Section 2") End If End Sub Sub CreateTree(ByVal NodeText As String) ' Create the root node using the default constructor. Dim root As TreeNode = New TreeNode root.Text = NodeText ' Use the ChildNodes property of the root TreeNode to add child nodes. ' Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(New TreeNode("Topic 1")) ' Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2")) ' Create the node using the constructor that takes the text, value, ' and imageUrl parameters. root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg")) ' Create the node using the constructor that takes the text, value, ' imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")) ' Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root) End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Init(Object sender, EventArgs e) { if(!IsPostBack) { // Add the first tree to the TreeView control. CreateTree("Section 1"); // Add the second tree to the TreeView control. CreateTree("Section 2"); } } void CreateTree(String NodeText) { // Create the root node using the default constructor. TreeNode root = new TreeNode(); root.Text = NodeText; // Use the ChildNodes property of the root TreeNode to add child nodes. // Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(new TreeNode("Topic 1")); // Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2")); // Create the node using the constructor that takes the text, value, // and imageUrl parameters. root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg")); // Create the node using the constructor that takes the text, value, // imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")); // Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root); } </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, String, String, String, String)
アセンブリ: System.Web (system.web.dll 内)

Public Sub New ( _ text As String, _ value As String, _ imageUrl As String, _ navigateUrl As String, _ target As String _ )
Dim text As String Dim value As String Dim imageUrl As String Dim navigateUrl As String Dim target As String Dim instance As New TreeNode(text, value, imageUrl, navigateUrl, target)
public: TreeNode ( String^ text, String^ value, String^ imageUrl, String^ navigateUrl, String^ target )
public function TreeNode ( text : String, value : String, imageUrl : String, navigateUrl : String, target : String )

このコンストラクタを使用して、text パラメータで指定されたテキスト、value パラメータで指定された値、imageUrl パラメータで指定されたイメージの URL、navigateUrl パラメータで指定されたナビゲーション URL、および target パラメータで指定された表示先で、TreeNode クラスの新しいインスタンスを初期化します。
TreeNode のインスタンスの初期プロパティ値を次の表に示します。

このコンストラクタを使用して、TreeView コントロールにノードを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Add the first tree to the TreeView control. CreateTree("Section 1") ' Add the second tree to the TreeView control. CreateTree("Section 2") End If End Sub Sub CreateTree(ByVal NodeText As String) ' Create the root node using the default constructor. Dim root As TreeNode = New TreeNode root.Text = NodeText ' Use the ChildNodes property of the root TreeNode to add child nodes. ' Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(New TreeNode("Topic 1")) ' Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2")) ' Create the node using the constructor that takes the text, value, ' and imageUrl parameters. root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg")) ' Create the node using the constructor that takes the text, value, ' imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")) ' Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root) End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Init(Object sender, EventArgs e) { if(!IsPostBack) { // Add the first tree to the TreeView control. CreateTree("Section 1"); // Add the second tree to the TreeView control. CreateTree("Section 2"); } } void CreateTree(String NodeText) { // Create the root node using the default constructor. TreeNode root = new TreeNode(); root.Text = NodeText; // Use the ChildNodes property of the root TreeNode to add child nodes. // Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(new TreeNode("Topic 1")); // Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2")); // Create the node using the constructor that takes the text, value, // and imageUrl parameters. root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg")); // Create the node using the constructor that takes the text, value, // imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")); // Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root); } </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (TreeView, Boolean)
アセンブリ: System.Web (system.web.dll 内)


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ (String, String, String)
アセンブリ: System.Web (system.web.dll 内)

Dim text As String Dim value As String Dim imageUrl As String Dim instance As New TreeNode(text, value, imageUrl)

このコンストラクタを使用して、text パラメータで指定されたテキスト、value パラメータで指定された値、および imageUrl パラメータで指定されたイメージの URL で、TreeNode クラスの新しいインスタンスを初期化します。
TreeNode のインスタンスの初期プロパティ値を次の表に示します。

このコンストラクタを使用して、TreeView コントロールにノードを動的に追加する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Add the first tree to the TreeView control. CreateTree("Section 1") ' Add the second tree to the TreeView control. CreateTree("Section 2") End If End Sub Sub CreateTree(ByVal NodeText As String) ' Create the root node using the default constructor. Dim root As TreeNode = New TreeNode root.Text = NodeText ' Use the ChildNodes property of the root TreeNode to add child nodes. ' Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(New TreeNode("Topic 1")) ' Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(New TreeNode("Topic 2", "Value 2")) ' Create the node using the constructor that takes the text, value, ' and imageUrl parameters. root.ChildNodes.Add(New TreeNode("Topic 3", "Value 3", "Image1.jpg")) ' Create the node using the constructor that takes the text, value, ' imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(New TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")) ' Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root) End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Init(Object sender, EventArgs e) { if(!IsPostBack) { // Add the first tree to the TreeView control. CreateTree("Section 1"); // Add the second tree to the TreeView control. CreateTree("Section 2"); } } void CreateTree(String NodeText) { // Create the root node using the default constructor. TreeNode root = new TreeNode(); root.Text = NodeText; // Use the ChildNodes property of the root TreeNode to add child nodes. // Create the node using the constructor that takes the text parameter. root.ChildNodes.Add(new TreeNode("Topic 1")); // Create the node using the constructor that takes the text and value parameters. root.ChildNodes.Add(new TreeNode("Topic 2", "Value 2")); // Create the node using the constructor that takes the text, value, // and imageUrl parameters. root.ChildNodes.Add(new TreeNode("Topic 3", "Value 3", "Image1.jpg")); // Create the node using the constructor that takes the text, value, // imageUrl, navigateUrl, and target parameters. root.ChildNodes.Add(new TreeNode("Topic 4", "Value 4", "Image1.jpg", "http://www.microsoft.com", "_blank")); // Add the root node to the Nodes collection of the TreeView control. DynamicTreeView.Nodes.Add(root); } </script> <html> <body> <form runat="server"> <h3>TreeNode Constructor Example</h3> <asp:TreeView id="DynamicTreeView" EnableClientScript="false" InitialExpandDepth="2" runat="server"> </asp:TreeView> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNode コンストラクタ

名前 | 説明 |
---|---|
TreeNode () | テキストや値を使用せずに、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String) | テキストを指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, String) | テキストと値を指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (TreeView, Boolean) | 所有者を指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, String, String) | テキスト、値、およびイメージの URL を指定して、TreeNode クラスの新しいインスタンスを初期化します。 |
TreeNode (String, String, String, String, String) | テキスト、値、イメージの URL、ナビゲーション URL、および表示先を指定して、TreeNode クラスの新しいインスタンスを初期化します。 |

- TreeNode コンストラクタ ()のページへのリンク