TreeNode コンストラクタ ()とは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > TreeNode コンストラクタ ()の意味・解説 

TreeNode コンストラクタ ()

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

テキストや値を使用せずに、TreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタ使用して、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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
Nodes
ChildNodes

TreeNode コンストラクタ ()

TreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

テキストと値を指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタ使用して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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ

TreeNode クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

TreeNode クラス
TreeNode メンバ
System.Windows.Forms 名前空間
TreeView
TreeNodeCollection

TreeNode コンストラクタ (SerializationInfo, StreamingContext)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

シリアル化情報コンテキスト指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Protected Sub New ( _
    serializationInfo As SerializationInfo, _
    context As StreamingContext _
)
Dim serializationInfo As SerializationInfo
Dim context As StreamingContext

Dim instance As New TreeNode(serializationInfo,
 context)
protected TreeNode (
    SerializationInfo serializationInfo,
    StreamingContext context
)
protected:
TreeNode (
    SerializationInfo^ serializationInfo, 
    StreamingContext context
)
protected TreeNode (
    SerializationInfo serializationInfo, 
    StreamingContext context
)
protected function TreeNode (
    serializationInfo : SerializationInfo, 
    context : StreamingContext
)

パラメータ

serializationInfo

クラスを逆シリアル化するためのデータ格納している SerializationInfo。

context

シリアル化ストリームソースおよびデスティネーション格納している StreamingContext。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String)

ラベル テキスト指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

TreeView コントロール顧客情報表示するコード例次に示しますルート ツリー ノード顧客名が表示され、各顧客割り当てられ発注番号が子ツリー ノード表示されます。この例では、1,000 人の顧客表示され顧客ごとに 15発注内容示されます。BeginUpdate メソッドと EndUpdate メソッド使用すると、TreeView は再描画されません。TreeViewTreeNode オブジェクト作成して描画する間、待機 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String, Int32, Int32, TreeNode[])

ラベル テキスト、子ツリー ノード、およびツリー ノード選択されているときと選択されていないときに表示するイメージそれぞれ指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: 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,
    TreeNode[] children
)
public:
TreeNode (
    String^ text, 
    int imageIndex, 
    int selectedImageIndex, 
    array<TreeNode^>^ children
)
public TreeNode (
    String text, 
    int imageIndex, 
    int selectedImageIndex, 
    TreeNode[] children
)
public function TreeNode (
    text : String, 
    imageIndex : int, 
    selectedImageIndex : int, 
    children : TreeNode[]
)

パラメータ

text

新しツリー ノードラベル Text

imageIndex

ツリー ノード選択されていないときに表示する Imageインデックス値。

selectedImageIndex

ツリー ノード選択されているときに表示する Imageインデックス値。

children

TreeNode オブジェクト配列

解説解説
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String, TreeNode[])

指定したラベル テキストと子ツリー ノード使用してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String, Int32, Int32)

ラベル テキストと、ツリー ノード選択されているときと選択されていないときに表示するイメージそれぞれ指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub New ( _
    text As String, _
    imageIndex As Integer, _
    selectedImageIndex As Integer _
)
Dim text As String
Dim imageIndex As Integer
Dim selectedImageIndex As Integer

Dim instance As New TreeNode(text,
 imageIndex, selectedImageIndex)
public TreeNode (
    string text,
    int imageIndex,
    int selectedImageIndex
)
public:
TreeNode (
    String^ text, 
    int imageIndex, 
    int selectedImageIndex
)
public TreeNode (
    String text, 
    int imageIndex, 
    int selectedImageIndex
)
public function TreeNode (
    text : String, 
    imageIndex : int, 
    selectedImageIndex : int
)

パラメータ

text

新しツリー ノードラベル Text

imageIndex

ツリー ノード選択されていないときに表示する Imageインデックス値。

selectedImageIndex

ツリー ノード選択されているときに表示する Imageインデックス値。

解説解説
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TreeNode コンストラクタ (String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

テキスト指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタ使用して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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
Text
Nodes
ChildNodes

TreeNode コンストラクタ (String, String, String, String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

テキスト、値、イメージURLナビゲーション URL、および表示先を指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタ使用して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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
Text
Value
ImageUrl
NavigateUrl
Target
Nodes
ChildNodes

TreeNode コンストラクタ (TreeView, Boolean)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

所有者指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Protected Friend Sub New
 ( _
    owner As TreeView, _
    isRoot As Boolean _
)
Dim owner As TreeView
Dim isRoot As Boolean

Dim instance As New TreeNode(owner,
 isRoot)
protected internal TreeNode (
    TreeView owner,
    bool isRoot
)
protected public:
TreeNode (
    TreeView^ owner, 
    bool isRoot
)
protected TreeNode (
    TreeView owner, 
    boolean isRoot
)

パラメータ

owner

新しTreeNode格納する TreeView。

isRoot

TreeNodeルート ノードである場合trueそれ以外場合false

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeNodeTypes

TreeNode コンストラクタ (String, String, String)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

テキスト、値、およびイメージURL指定してTreeNode クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
使用例使用例

このコンストラクタ使用して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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNode クラス
TreeNode メンバ
System.Web.UI.WebControls 名前空間
TreeView
Text
Value
ImageUrl
Nodes
ChildNodes

TreeNode コンストラクタ




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TreeNode コンストラクタ ()」の関連用語

TreeNode コンストラクタ ()のお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNode コンストラクタ ()のページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS