TreeView.Nodes 속성
tree view 컨트롤에 할당된 트리 노드의 컬렉션을 가져옵니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
<LocalizableAttribute(True)> _
Public ReadOnly Property Nodes As TreeNodeCollection
‘사용 방법
Dim instance As TreeView
Dim value As TreeNodeCollection
value = instance.Nodes
[LocalizableAttribute(true)]
public TreeNodeCollection Nodes { get; }
[LocalizableAttribute(true)]
public:
property TreeNodeCollection^ Nodes {
TreeNodeCollection^ get ();
}
/** @property */
public TreeNodeCollection get_Nodes ()
public function get Nodes () : TreeNodeCollection
속성 값
tree view 컨트롤에 할당된 트리 노드를 나타내는 TreeNodeCollection입니다.
설명
Nodes 속성은 각각 해당 TreeNodeCollection을 포함할 수 있는 Nodes 속성을 갖는 TreeNode 개체의 컬렉션을 보유합니다. 이렇게 트리 노드가 중첩되면 트리 구조를 탐색하기 어려울 수 있으나 FullPath 속성으로 트리 구조 내의 사용자 위치를 보다 쉽게 확인할 수 있습니다.
예제
다음 코드 예제에서는 TreeView 컨트롤에 고객 정보를 표시합니다. 루트 트리 노드에는 고객 이름이 표시되고 자식 트리 노드에는 각 고객에게 할당된 주문 번호가 표시됩니다. 이 예제에서는 주문을 15개씩 보유하고 있는 1000명의 고객이 표시됩니다. BeginUpdate 및 EndUpdate 메서드를 사용하여 TreeView의 다시 그리기가 억제되고 TreeView에서 TreeNode 개체를 만들고 그리는 동안 대기 중인 Cursor가 표시됩니다. 이 예제를 실행하려면 Order
개체의 컬렉션을 저장할 수 있는 Customer
개체가 있어야 합니다. 또한 Form에 TreeView 컨트롤의 인스턴스가 있어야 합니다.
' 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에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원
참고 항목
참조
TreeView 클래스
TreeView 멤버
System.Windows.Forms 네임스페이스
TreeNodeCollection 클래스
TreeView.Nodes 속성