ListView.EndUpdate 메서드

정의

BeginUpdate() 메서드에 의해 그리기가 중지된 후 list view 컨트롤을 다시 그립니다.

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

예제

다음 코드 예제에서는 확인란을 포함 하도록 컨트롤을 ListView 초기화 하는 방법을 보여 줍니다. 또한 해당 및 EndUpdate 메서드를 사용하는 방법을 BeginUpdate 보여 줍니다. 이 예제를 실행하려면 다음 코드를 명명ListView1된 양식 ListView 에 붙여넣습니다. 폼의 InitializeListView 생성자 또는 Load 메서드에서 메서드를 호출합니다.

void InitializeListView()
{
   this->ListView1 = gcnew System::Windows::Forms::ListView;
   
   // Set properties such as BackColor and DockStyle and Location.
   this->ListView1->BackColor = System::Drawing::SystemColors::Control;
   this->ListView1->Dock = System::Windows::Forms::DockStyle::Top;
   this->ListView1->Location = System::Drawing::Point( 0, 0 );
   this->ListView1->Size = System::Drawing::Size( 292, 130 );
   this->ListView1->View = System::Windows::Forms::View::Details;
   this->ListView1->HideSelection = false;
   
   // Allow the user to select multiple items.
   this->ListView1->MultiSelect = true;
   
   // Show CheckBoxes in the ListView.
   this->ListView1->CheckBoxes = true;
   
   //Set the column headers and populate the columns.
   ListView1->HeaderStyle = ColumnHeaderStyle::Nonclickable;
   ColumnHeader^ columnHeader1 = gcnew ColumnHeader;
   columnHeader1->Text = "Breakfast Choices";
   columnHeader1->TextAlign = HorizontalAlignment::Left;
   columnHeader1->Width = 146;
   ColumnHeader^ columnHeader2 = gcnew ColumnHeader;
   columnHeader2->Text = "Price Each";
   columnHeader2->TextAlign = HorizontalAlignment::Center;
   columnHeader2->Width = 142;
   this->ListView1->Columns->Add( columnHeader1 );
   this->ListView1->Columns->Add( columnHeader2 );
   array<String^>^foodList = {"Juice","Coffee","Cereal & Milk","Fruit Plate","Toast & Jelly","Bagel & Cream Cheese"};
   array<String^>^foodPrice = {"1.09","1.09","2.19","2.79","2.09","2.69"};
   int count;
   
   // Members are added one at a time, so call BeginUpdate to ensure 
   // the list is painted only once, rather than as each list item is added.
   ListView1->BeginUpdate();
   for ( count = 0; count < foodList->Length; count++ )
   {
      ListViewItem^ listItem = gcnew ListViewItem( foodList[ count ] );
      listItem->SubItems->Add( foodPrice[ count ] );
      ListView1->Items->Add( listItem );
   }
   
   //Call EndUpdate when you finish adding items to the ListView.
   ListView1->EndUpdate();
   this->Controls->Add( this->ListView1 );
}
private void InitializeListView()
{
    this.ListView1 = new System.Windows.Forms.ListView();

    // Set properties such as BackColor and DockStyle and Location.
    this.ListView1.BackColor = System.Drawing.SystemColors.Control;
    this.ListView1.Dock = System.Windows.Forms.DockStyle.Top;
    this.ListView1.Location = new System.Drawing.Point(0, 0);
    this.ListView1.Size = new System.Drawing.Size(292, 130);
    this.ListView1.View = System.Windows.Forms.View.Details;
    this.ListView1.HideSelection = false;

    // Allow the user to select multiple items.
    this.ListView1.MultiSelect = true;

    // Show CheckBoxes in the ListView.
    this.ListView1.CheckBoxes = true;
    
    //Set the column headers and populate the columns.
    ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable;
    
    ColumnHeader columnHeader1 = new ColumnHeader();
    columnHeader1.Text = "Breakfast Choices";
    columnHeader1.TextAlign = HorizontalAlignment.Left;
    columnHeader1.Width = 146;

    ColumnHeader columnHeader2 = new ColumnHeader();
    columnHeader2.Text = "Price Each";
    columnHeader2.TextAlign = HorizontalAlignment.Center;
    columnHeader2.Width = 142;

    this.ListView1.Columns.Add(columnHeader1);
    this.ListView1.Columns.Add(columnHeader2);

    string[] foodList = new string[]{"Juice", "Coffee", 
        "Cereal & Milk", "Fruit Plate", "Toast & Jelly", 
        "Bagel & Cream Cheese"};

    string[] foodPrice = new string[]{"1.09", "1.09", "2.19", 
        "2.79", "2.09", "2.69"};
    
    int count;

    // Members are added one at a time, so call BeginUpdate to ensure 
    // the list is painted only once, rather than as each list item is added.
    ListView1.BeginUpdate();

    for(count = 0; count < foodList.Length; count++)
    {
        ListViewItem listItem = new ListViewItem(foodList[count]);
        listItem.SubItems.Add(foodPrice[count]);
        ListView1.Items.Add(listItem);
    }

    //Call EndUpdate when you finish adding items to the ListView.
    ListView1.EndUpdate();
    this.Controls.Add(this.ListView1);
}
Private Sub InitializeListView()
    Me.ListView1 = New System.Windows.Forms.ListView

    ' Set properties such as BackColor, Location and Size
    Me.ListView1.BackColor = System.Drawing.SystemColors.Control
    Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
    Me.ListView1.Location = New System.Drawing.Point(0, 0)
    Me.ListView1.Size = New System.Drawing.Size(292, 130)
    Me.ListView1.View = System.Windows.Forms.View.Details
    Me.ListView1.HideSelection = False

    ' Allow user to select multiple items.
    Me.ListView1.MultiSelect = True

    ' Show check boxes in the ListView.
    Me.ListView1.CheckBoxes = True

    'Set the column headers and populate the columns.
    ListView1.HeaderStyle = ColumnHeaderStyle.Nonclickable
    Dim columnHeader1 As New ColumnHeader
    With columnHeader1
        .Text = "Breakfast Choices"
        .TextAlign = HorizontalAlignment.Left
        .Width = 146
    End With
    Dim columnHeader2 As New ColumnHeader
    With columnHeader2
        .Text = "Price Each"
        .TextAlign = HorizontalAlignment.Center
        .Width = 142
    End With
    Me.ListView1.Columns.Add(columnHeader1)
    Me.ListView1.Columns.Add(columnHeader2)
    Dim foodList() As String = New String() {"Juice", "Coffee", _
        "Cereal & Milk", "Fruit Plate", "Toast & Jelly", _
        "Bagel & Cream Cheese"}

    Dim foodPrice() As String = New String() {"1.09", "1.09", "2.19", _
        "2.79", "2.09", "2.69"}
    Dim count As Integer

    ' Members are added one at a time, so call BeginUpdate to ensure 
    ' the list is painted only once, rather than as each list item is added.
    ListView1.BeginUpdate()

    For count = 0 To foodList.Length - 1
        Dim listItem As New ListViewItem(foodList(count))
        listItem.SubItems.Add(foodPrice(count))
        ListView1.Items.Add(listItem)
    Next

    'Call EndUpdate when you finish adding items to the ListView.
    ListView1.EndUpdate()
    Me.Controls.Add(Me.ListView1)
End Sub

설명

여러 항목을 ListView 추가하는 기본 방법은 (의 속성을 통해 액세스)의 ListView.ListViewItemCollection 메서드를 Items 사용하는 AddRange 것입니다ListView. 이렇게 하면 단일 작업에서 목록에 항목 배열을 추가할 수 있습니다. 그러나 클래스의 ListView.ListViewItemCollection 메서드를 사용하여 Add 항목을 한 번에 하나씩 추가하려는 경우 이 메서드를 사용하여 BeginUpdate 항목을 추가할 때마다 컨트롤이 다시 그려 ListView 지는 것을 방지할 수 있습니다. 컨트롤에 항목을 추가하는 작업을 완료했으면 메서드를 EndUpdate 호출하여 다시 칠할 수 있도록 합니다 ListView . 이러한 방식으로 항목을 추가하면 많은 수의 항목이 컨트롤에 ListView 추가될 때 깜박이는 그리기를 방지할 수 있습니다.

두 번 EndUpdate 이상 호출되는 경우 BeginUpdate 해당하는 횟수만큼 호출해야 합니다. 마지막 호출까지 EndUpdateListView 다시 표시되지 않습니다. 이 외에는 여러 호출에 BeginUpdate 영향을 주지 않습니다.

적용 대상

추가 정보