Assembly: System.Windows.Forms (in system.windows.forms.dll)
Public Sub EndUpdate
Dim instance As TreeView instance.EndUpdate
public void EndUpdate ()
public: void EndUpdate ()
public void EndUpdate ()
public function EndUpdate ()
Per gestire le prestazioni mentre gli elementi vengono aggiunti singolarmente al controllo TreeView, chiamare il metodo BeginUpdate. Il metodo BeginUpdate impedisce al controllo di essere ridisegnato prima della chiamata del metodo EndUpdate.
Il modo migliore per aggiungere elementi a un controllo della visualizzazione struttura è quello di utilizzare il metodo AddRange per aggiungere una matrice degli elementi del nodo della struttura a una visualizzazione struttura. Tuttavia, se si desidera aggiungere un solo elemento per volta, utilizzare il metodo BeginUpdate per impedire al controllo TreeView di essere ridisegnato durante le operazioni di aggiunta. Per consentire al controllo di essere ridisegnato, chiamare il metodo EndUpdate una volta aggiunti tutti i nodi della struttura alla visualizzazione struttura.
Nell'esempio di codice riportato di seguito vengono visualizzate informazioni relative ai clienti in un controllo TreeView. Nei nodi principali della struttura sono visualizzati i nomi dei clienti mentre nei nodi figlio della struttura sono visualizzati i numeri di ordine assegnati a ciascun cliente. In questo esempio, vengono visualizzati 1.000 clienti con 15 ordini ciascuno. Per evitare di ridisegnare il controllo TreeView, utilizzare i metodi BeginUpdate e EndUpdate; viene visualizzato un oggetto Cursor di attesa mentre nel controllo TreeView vengono creati e disegnati gli oggetti TreeNode. Per eseguire questo esempio è necessario che si disponga di un oggetto Customer che possa contenere un insieme di oggetti Order. Si richiede inoltre che nella directory dell'applicazione sia presente un file di cursore denominato MyWait.cur e che si sia creata un'istanza di un controllo TreeView su un oggetto 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 per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.