ListBox.BeginUpdate Yöntem

Tanım

Yöntem çağrılana kadar EndUpdate() denetimin ListBox çizim yapmasını engelleyerek öğeler bir kerede bir öğeye eklenirken performansı korur.

public:
 void BeginUpdate();
public void BeginUpdate ();
member this.BeginUpdate : unit -> unit
Public Sub BeginUpdate ()

Örnekler

Aşağıdaki kod örneği, öğesine beş bin öğe ListBoxeklerken ve EndUpdate yöntemlerini kullanırBeginUpdate. Bu örnek, adlı listBox1bir ListBox denetimin öğesine eklenmesini Form ve bu yöntemin forma yerleştirilmesini ve ondan çağrılsını gerektirir.

void AddToMyListBox()
{
   // Stop the ListBox from drawing while items are added.
   listBox1->BeginUpdate();

   // Loop through and add five thousand new items.
   for ( int x = 1; x < 5000; x++ )
   {
      listBox1->Items->Add( String::Format( "Item {0}", x ) );
   }
   listBox1->EndUpdate();
}
public void AddToMyListBox()
{
   // Stop the ListBox from drawing while items are added.
   listBox1.BeginUpdate();

   // Loop through and add five thousand new items.
   for(int x = 1; x < 5000; x++)
   {
      listBox1.Items.Add("Item " + x.ToString());   
   }
   // End the update process and force a repaint of the ListBox.
   listBox1.EndUpdate();
}
Public Sub AddToMyListBox()
    ' Stop the ListBox from drawing while items are added.
    listBox1.BeginUpdate()
       
    ' Loop through and add five thousand new items.
    Dim x As Integer
    For x = 1 To 4999
        listBox1.Items.Add("Item " & x.ToString())
    Next x
    ' End the update process and force a repaint of the ListBox.
    listBox1.EndUpdate()
End Sub

Açıklamalar

öğesine birden çok öğe ListBox eklemenin tercih edilen yolu sınıfının yöntemini ListBox.ObjectCollection kullanmaktır AddRange (özelliği ListBoxaracılığıylaItems). Bu, tek bir işlemde listeye bir öğe dizisi eklemenize olanak tanır. Ancak, sınıfın yöntemini ListBox.ObjectCollection kullanarak Add öğeleri birer birer eklemek istiyorsanız, denetimin BeginUpdate listeye her öğe eklendiğinde yeniden boyanmasını ListBox önlemek için yöntemini kullanabilirsiniz. Listeye öğe ekleme görevini tamamladıktan sonra, öğesinin yeniden boyanmasını EndUpdate etkinleştirmek ListBox için yöntemini çağırın. Öğe eklemenin bu yolu, listeye çok sayıda öğe eklendiğinde öğesinin titreşimli çizimini ListBox engelleyebilir.

Şunlara uygulanır

Ayrıca bkz.