다음을 통해 공유


ListBox.BeginUpdate 메서드

EndUpdate 메서드가 호출될 때까지 해당 컨트롤이 그려지지 않도록 하여 항목이 한 번에 하나씩 ListBox에 추가되는 동안 성능을 유지합니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
Public Sub BeginUpdate
‘사용 방법
Dim instance As ListBox

instance.BeginUpdate
public void BeginUpdate ()
public:
void BeginUpdate ()
public void BeginUpdate ()
public function BeginUpdate ()

설명

ListBox에 여러 항목을 추가할 때 선호되는 방법은 ListBoxItems 속성을 통해 ListBox.ObjectCollection 클래스의 AddRange 메서드를 사용하는 것입니다. 이렇게 하면 단일 작업에서 항목 배열을 목록에 추가할 수 있습니다. 그러나 ListBox.ObjectCollection 클래스의 Add 메서드를 사용하여 한 번에 하나씩 항목을 추가하려면 BeginUpdate 메서드를 사용하여 항목이 목록에 추가될 때마다 해당 컨트롤이 ListBox를 다시 그리지 않도록 합니다. 목록에 항목을 추가하는 작업이 끝나면 EndUpdate 메서드를 호출하여 ListBox를 다시 그릴 수 있습니다. 이러한 방법으로 항목을 추가하면 목록에 많은 수의 항목이 추가될 때 ListBox가 깜박이지 않고 표시됩니다.

예제

다음 코드 예제에서는 ListBox에 5천 개의 항목을 추가하는 동안 BeginUpdateEndUpdate 메서드를 사용합니다. 이 예제를 실행하려면 listBox1이라는 ListBox 컨트롤이 Form에 추가되어야 하며, 이 메서드가 폼 내에 있고 해당 폼에서 호출되어야 합니다.

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
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();
}
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.get_Items().Add(("Item" + (new Integer(x)).ToString()));
    }

    // End the update process and force a repaint of the ListBox.
    listBox1.EndUpdate();
} //AddToMyListBox
function AddToMyListBox(){
    // Stop the ListBox from drawing while items are added.
    listBox1.BeginUpdate()
       
    // Loop through and add five thousand new items.
    for(var x = 0; x < 5000; x++)
        listBox1.Items.Add("Item " + x.ToString())
    // End the update process and force a repaint of the ListBox.
    listBox1.EndUpdate()
}

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0에서 지원

참고 항목

참조

ListBox 클래스
ListBox 멤버
System.Windows.Forms 네임스페이스
EndUpdate