Share via


방법: Windows Forms ListView 컨트롤을 사용하여 항목 추가 및 제거

Windows Forms ListView 컨트롤에 항목을 추가하는 프로세스는 주로 항목을 지정하고 해당 컨트롤에 속성을 할당하는 것으로 구성됩니다. 목록 항목 추가 또는 제거는 언제든지 수행할 수 있습니다.

프로그래밍 방식으로 항목을 추가하려면

  1. Items 속성의 Add 메서드를 사용합니다.

    // Adds a new item with ImageIndex 3
    listView1.Items.Add("List item text", 3);
    
    
    ' Adds a new item with ImageIndex 3
    ListView1.Items.Add("List item text", 3)
    
    

프로그래밍 방식으로 항목을 제거하려면

  1. Items 속성의 RemoveAt 또는 Clear 메서드를 사용합니다. RemoveAt 메서드는 단일 항목을 제거합니다. Clear 메서드는 목록에서 모든 항목을 제거합니다.

    // Removes the first item in the list.
    listView1.Items.RemoveAt(0);
    // Clears all the items.
    listView1.Items.Clear();
    
    
    ' Removes the first item in the list.
    ListView1.Items.RemoveAt(0)
    ' Clears all items:
    ListView1.Items.Clear()
    
    

참고 항목