Bagikan melalui


ListBox.BeginUpdate Metode

Definisi

Mempertahankan performa saat item ditambahkan ke ListBox item sekaligus dengan mencegah kontrol menggambar hingga metode dipanggil EndUpdate() .

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

Contoh

Contoh kode berikut menggunakan BeginUpdate metode dan EndUpdate sambil menambahkan lima ribu item ke ListBox. Contoh ini mengharuskan ListBox kontrol, bernama listBox1, telah ditambahkan ke Form dan bahwa metode ini ditempatkan dalam formulir dan dipanggil darinya.

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

Keterangan

Cara yang disukai untuk menambahkan beberapa item ke ListBox adalah dengan menggunakan AddRange metode ListBox.ObjectCollection kelas (melalui Items properti ListBox). Ini memungkinkan Anda menambahkan array item ke daftar dalam satu operasi. Namun, jika Anda ingin menambahkan item satu per satu menggunakan Add metode ListBox.ObjectCollection kelas , Anda dapat menggunakan BeginUpdate metode untuk mencegah kontrol mengecat ListBox ulang setiap kali item ditambahkan ke daftar. Setelah Anda menyelesaikan tugas menambahkan item ke daftar, panggil EndUpdate metode untuk mengaktifkan ListBox pengecatan ulang. Cara menambahkan item ini dapat mencegah gambar ListBox berkedot saat sejumlah besar item ditambahkan ke daftar.

Berlaku untuk

Lihat juga