Bagikan melalui


ListBox.EndUpdate Metode

Definisi

Melanjutkan pengecatan ListBox kontrol setelah lukisan ditangguhkan oleh BeginUpdate() metode .

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

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 item ke ListBox adalah dengan menggunakan AddRange metode ListBox.ObjectCollection kelas (melalui Items properti ListBox). Ini memungkinkan Anda untuk menambahkan array item ke daftar pada satu waktu. 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