다음을 통해 공유


ListViewItem 클래스

ListView 컨트롤의 항목을 나타냅니다.

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

구문

‘선언
<SerializableAttribute> _
Public Class ListViewItem
    Implements ICloneable, ISerializable
‘사용 방법
Dim instance As ListViewItem
[SerializableAttribute] 
public class ListViewItem : ICloneable, ISerializable
[SerializableAttribute] 
public ref class ListViewItem : ICloneable, ISerializable
/** @attribute SerializableAttribute() */ 
public class ListViewItem implements ICloneable, ISerializable
SerializableAttribute 
public class ListViewItem implements ICloneable, ISerializable

설명

ListView 컨트롤은 항목 목록을 표시한다는 점에서 ListBox와 비슷합니다. 하지만 ListView 컨트롤에는 항목을 표시하는 방법이 다양하다는 점이 다릅니다. ListViewItem 클래스는 ListView 컨트롤에 표시되는 항목과 관련된 모양, 동작 및 데이터를 정의합니다. ListViewItem 개체는 서로 다른 네 종류의 보기 중 하나로 ListView 컨트롤에 표시될 수 있습니다. 항목은 큰 아이콘, 작은 아이콘 또는 세로 목록의 작은 아이콘으로 표시될 수 있습니다. 항목에는 부모 항목과 관련된 정보가 들어 있는 하위 항목이 있을 수 있습니다. 넷째 보기 스타일인 자세히 보기를 사용하면 하위 항목에 표시되는 정보를 식별하는 데 사용할 수 있는 열 머리글이 있는 표 형식으로 항목과 하위 항목을 표시할 수 있습니다.

ListViewItem 클래스의 속성 대부분은 연결되어 있는 ListView 컨트롤에서 항목의 표시를 변경하는 방법을 제공합니다. BackColor, ForeColorFont 속성을 사용하면 ListView 컨트롤에서 항목의 텍스트가 표시되는 방법을 변경할 수 있습니다. ImageIndex 속성을 사용하면 ListViewLargeImageList 또는 SmallImageList 속성을 설정하여 ListView 컨트롤에 할당된 ImageList에서 로드할 이미지를 지정할 수 있습니다. CheckedListBox 컨트롤과 비슷한 방법으로 항목을 선택할 수 있도록 항목에 확인란을 표시할 수 있습니다. Checked 속성을 사용하면 런타임에 항목의 선택 여부를 확인하거나 확인란의 선택 상태를 변경할 수 있습니다. 연결된 ListView 컨트롤의 View 속성이 Details로 설정되어 있고 열이 ListView 컨트롤의 ListView.ColumnHeaderCollection에 정의되어 있으면 항목에는 하위 항목을 제한 없이 표시될 수 있습니다. ListViewItem.ListViewSubItemCollection 클래스의 Add 메서드를 호출하여 항목에 하위 항목을 추가할 수 있습니다. SubItems 속성을 사용하면 ListViewItem.ListViewSubItemCollection 클래스와 그 멤버에 액세스할 수 있습니다.

ListViewItem 클래스의 일부 속성과 메서드는 ListView 컨트롤에서 항목에 대해 고유한 속성과 메서드입니다. 예를 들어, EnsureVisible 메서드는 ListView 버전의 메서드와 비슷하지만 ListViewItem 버전은 현재 항목에만 영향을 줍니다.

ListViewItem 클래스는 ListView 메서드 버전이 아닌 메서드도 제공합니다. BeginEdit 메서드는 항목의 텍스트를 편집 모드로 만들므로 사용자는 ListView 컨트롤의 LabelEdit 속성이 true인 경우 항목의 텍스트를 변경할 수 있습니다. Clone 메서드를 사용하면 기존 ListViewItem 개체의 사본을 만들 수 있으므로 다른 ListView 컨트롤에서 다시 사용할 수 있습니다.

예제

다음 코드 예제에서는 ListViewItem 개체가 세 개 지정되어 있고, 각 항목에 대해 ListViewItem.ListViewSubItem 개체가 세 개씩 지정되어 있는 ListView 컨트롤을 만듭니다. 이 예제에서는 자세히 보기에 하위 항목을 표시하는 ColumnHeader 개체도 만듭니다. 또한 코드 예제에서는 ImageList 개체를 두 개 만들어 ListViewItem 개체에 대한 이미지를 제공합니다. 이런 ImageList 개체는 LargeImageListSmallImageList 속성에 추가됩니다. 이 예제에서는 다음과 같은 속성을 사용하여 ListView 컨트롤을 만듭니다.

해당 코드를 Form에 추가하고 폼의 생성자나 다른 메서드의 예제에서 만든 메서드를 호출해야 합니다. 이 예제를 실행하려면 MySmallImage1, MySmallImage2, MyLargeImage1MyLargeImage2라는 이미지도 C 드라이브의 루트 디렉터리에 있어야 합니다.

Private Sub CreateMyListView()
    ' Create a new ListView control.
    Dim listView1 As New ListView()
    listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200))

    ' Set the view to show details.
    listView1.View = View.Details
    ' Allow the user to edit item text.
    listView1.LabelEdit = True
    ' Allow the user to rearrange columns.
    listView1.AllowColumnReorder = True
    ' Display check boxes.
    listView1.CheckBoxes = True
    ' Select the item and subitems when selection is made.
    listView1.FullRowSelect = True
    ' Display grid lines.
    listView1.GridLines = True
    ' Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending

    ' Create three items and three sets of subitems for each item.
    Dim item1 As New ListViewItem("item1", 0)
    ' Place a check mark next to the item.
    item1.Checked = True
    item1.SubItems.Add("1")
    item1.SubItems.Add("2")
    item1.SubItems.Add("3")
    Dim item2 As New ListViewItem("item2", 1)
    item2.SubItems.Add("4")
    item2.SubItems.Add("5")
    item2.SubItems.Add("6")
    Dim item3 As New ListViewItem("item3", 0)
    ' Place a check mark next to the item.
    item3.Checked = True
    item3.SubItems.Add("7")
    item3.SubItems.Add("8")
    item3.SubItems.Add("9")

    ' Create columns for the items and subitems.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left)
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center)

    'Add the items to the ListView.
    listView1.Items.AddRange(New ListViewItem() {item1, item2, item3})

    ' Create two ImageList objects.
    Dim imageListSmall As New ImageList()
    Dim imageListLarge As New ImageList()

    ' Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage1.bmp"))
    imageListSmall.Images.Add(Bitmap.FromFile("C:\MySmallImage2.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage1.bmp"))
    imageListLarge.Images.Add(Bitmap.FromFile("C:\MyLargeImage2.bmp"))

    'Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge
    listView1.SmallImageList = imageListSmall

    ' Add the ListView to the control collection.
    Me.Controls.Add(listView1)
End Sub 'CreateMyListView
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

    // Set the view to show details.
    listView1.View = View.Details;
    // Allow the user to edit item text.
    listView1.LabelEdit = true;
    // Allow the user to rearrange columns.
    listView1.AllowColumnReorder = true;
    // Display check boxes.
    listView1.CheckBoxes = true;
    // Select the item and subitems when selection is made.
    listView1.FullRowSelect = true;
    // Display grid lines.
    listView1.GridLines = true;
    // Sort the items in the list in ascending order.
    listView1.Sorting = SortOrder.Ascending;
                
    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1",0);
    // Place a check mark next to the item.
    item1.Checked = true;
    item1.SubItems.Add("1");
    item1.SubItems.Add("2");
    item1.SubItems.Add("3");
    ListViewItem item2 = new ListViewItem("item2",1);
    item2.SubItems.Add("4");
    item2.SubItems.Add("5");
    item2.SubItems.Add("6");
    ListViewItem item3 = new ListViewItem("item3",0);
    // Place a check mark next to the item.
    item3.Checked = true;
    item3.SubItems.Add("7");
    item3.SubItems.Add("8");
    item3.SubItems.Add("9");

    // Create columns for the items and subitems.
    listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
            listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage1.bmp"));
    imageListSmall.Images.Add(Bitmap.FromFile("C:\\MySmallImage2.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage1.bmp"));
    imageListLarge.Images.Add(Bitmap.FromFile("C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.LargeImageList = imageListLarge;
    listView1.SmallImageList = imageListSmall;

    // Add the ListView to the control collection.
    this.Controls.Add(listView1);
}
private:
   void CreateMyListView()
   {
      // Create a new ListView control.
      ListView^ listView1 = gcnew ListView;
      listView1->Bounds = Rectangle(Point(10,10),System::Drawing::Size( 300, 200 ));

      // Set the view to show details.
      listView1->View = View::Details;

      // Allow the user to edit item text.
      listView1->LabelEdit = true;

      // Allow the user to rearrange columns.
      listView1->AllowColumnReorder = true;

      // Display check boxes.
      listView1->CheckBoxes = true;

      // Select the item and subitems when selection is made.
      listView1->FullRowSelect = true;

      // Display grid lines.
      listView1->GridLines = true;

      // Sort the items in the list in ascending order.
      listView1->Sorting = SortOrder::Ascending;

      // Create three items and three sets of subitems for each item.
      ListViewItem^ item1 = gcnew ListViewItem( "item1",0 );

      // Place a check mark next to the item.
      item1->Checked = true;
      item1->SubItems->Add( "1" );
      item1->SubItems->Add( "2" );
      item1->SubItems->Add( "3" );
      ListViewItem^ item2 = gcnew ListViewItem( "item2",1 );
      item2->SubItems->Add( "4" );
      item2->SubItems->Add( "5" );
      item2->SubItems->Add( "6" );
      ListViewItem^ item3 = gcnew ListViewItem( "item3",0 );

      // Place a check mark next to the item.
      item3->Checked = true;
      item3->SubItems->Add( "7" );
      item3->SubItems->Add( "8" );
      item3->SubItems->Add( "9" );

      // Create columns for the items and subitems.
      listView1->Columns->Add( "Item Column", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 2", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 3", -2, HorizontalAlignment::Left );
      listView1->Columns->Add( "Column 4", -2, HorizontalAlignment::Center );

      //Add the items to the ListView.
      array<ListViewItem^>^temp1 = {item1,item2,item3};
      listView1->Items->AddRange( temp1 );

      // Create two ImageList objects.
      ImageList^ imageListSmall = gcnew ImageList;
      ImageList^ imageListLarge = gcnew ImageList;

      // Initialize the ImageList objects with bitmaps.
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage1.bmp" ) );
      imageListSmall->Images->Add( Bitmap::FromFile( "C:\\MySmallImage2.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage1.bmp" ) );
      imageListLarge->Images->Add( Bitmap::FromFile( "C:\\MyLargeImage2.bmp" ) );

      //Assign the ImageList objects to the ListView.
      listView1->LargeImageList = imageListLarge;
      listView1->SmallImageList = imageListSmall;
      
      // Add the ListView to the control collection.
      this->Controls->Add( listView1 );
   }
private void CreateMyListView()
{
    // Create a new ListView control.
    ListView listView1 = new ListView();
    listView1.set_Bounds(new Rectangle(new Point(10, 10), 
        new Size(300, 200)));

    // Set the view to show details.
    listView1.set_View(View.Details);

    // Allow the user to edit item text.
    listView1.set_LabelEdit(true);

    // Allow the user to rearrange columns.
    listView1.set_AllowColumnReorder(true);

    // Display check boxes.
    listView1.set_CheckBoxes(true);

    // Select the item and subitems when selection is made.
    listView1.set_FullRowSelect(true);

    // Display grid lines.
    listView1.set_GridLines(true);

    // Sort the items in the list in ascending order.
    listView1.set_Sorting(SortOrder.Ascending);

    // Create three items and three sets of subitems for each item.
    ListViewItem item1 = new ListViewItem("item1", 0);

    // Place a check mark next to the item.
    item1.set_Checked(true);

    item1.get_SubItems().Add("1");
    item1.get_SubItems().Add("2");
    item1.get_SubItems().Add("3");

    ListViewItem item2 = new ListViewItem("item2", 1);
    item2.get_SubItems().Add("4");
    item2.get_SubItems().Add("5");
    item2.get_SubItems().Add("6");

    ListViewItem item3 = new ListViewItem("item3", 0);

    // Place a check mark next to the item.
    item3.set_Checked(true);

    item3.get_SubItems().Add("7");
    item3.get_SubItems().Add("8");
    item3.get_SubItems().Add("9");

    // Create columns for the items and subitems.
    listView1.get_Columns().Add("Item Column", -2, 
        HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 2", -2, HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 3", -2, HorizontalAlignment.Left);
    listView1.get_Columns().Add("Column 4", -2, HorizontalAlignment.Center);

    //Add the items to the ListView.
    listView1.get_Items().AddRange(new ListViewItem[] { item1, item2, 
        item3 });

    // Create two ImageList objects.
    ImageList imageListSmall = new ImageList();
    ImageList imageListLarge = new ImageList();

    // Initialize the ImageList objects with bitmaps.
    imageListSmall.get_Images().Add(Bitmap.FromFile(
        "C:\\MySmallImage1.bmp"));
    imageListSmall.get_Images().Add(Bitmap.FromFile(
        "C:\\MySmallImage2.bmp"));
    imageListLarge.get_Images().Add(Bitmap.FromFile(
        "C:\\MyLargeImage1.bmp"));
    imageListLarge.get_Images().Add(Bitmap.FromFile(
        "C:\\MyLargeImage2.bmp"));

    //Assign the ImageList objects to the ListView.
    listView1.set_LargeImageList(imageListLarge);
    listView1.set_SmallImageList(imageListSmall);

    // Add the ListView to the control collection.
    this.get_Controls().Add(listView1);
} //CreateMyListView

상속 계층 구조

System.Object
  System.Windows.Forms.ListViewItem

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, 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, 1.0에서 지원

참고 항목

참조

ListViewItem 멤버
System.Windows.Forms 네임스페이스
ListView 클래스
ListViewItem.ListViewSubItem

기타 리소스

ListView 컨트롤(Windows Forms)