ListBox.EndUpdate メソッド

定義

ListBox メソッドによって描画が中断された後、BeginUpdate() コントロールの描画を再開します。

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

次のコード例では、5,000 個の項目を BeginUpdate 追加するときに、メソッドと EndUpdate メソッドを ListBox使用します。 この例では、という名前listBox1ListBoxコントロールが a にForm追加され、このメソッドがフォーム内に配置され、そこから呼び出される必要があります。

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

注釈

項目を追加するListBox推奨される方法は、(クラスのプロパティをListBox.ObjectCollection介して) クラスのメソッドをItems使用AddRangeすることですListBox。 これにより、一度に項目の配列をリストに追加できます。 ただし、クラスのListBox.ObjectCollectionメソッドを使用してAdd一度に 1 つずつ項目を追加する場合は、このメソッドをBeginUpdate使用して、項目がリストに追加されるたびにコントロールが再描画ListBoxされないようにすることができます。 リストに項目を追加するタスクが完了したら、メソッドを EndUpdate 呼び出して再描画を ListBox 有効にします。 この方法で項目を追加すると、多数の ListBox 項目がリストに追加されたときのちらつきの描画を防ぐことができます。

適用対象

こちらもご覧ください