ListViewItem 클래스

정의

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

public ref class ListViewItem : ICloneable, System::Runtime::Serialization::ISerializable
[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ListViewItemConverter))]
[System.Serializable]
public class ListViewItem : ICloneable, System.Runtime.Serialization.ISerializable
[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.ListViewItemConverter))>]
[<System.Serializable>]
type ListViewItem = class
    interface ICloneable
    interface ISerializable
Public Class ListViewItem
Implements ICloneable, ISerializable
상속
ListViewItem
특성
구현

예제

다음 코드 예제를 ListView 3 개를 사용 하 여 컨트롤 ListViewItem 지정 된 개체 및 3 ListViewItem.ListViewSubItem 각 항목에 대해 지정 된 개체입니다. 예제에서는 ColumnHeader 하위 항목 세부 정보 보기에 표시할 개체입니다. 두 개의 ImageList 이미지를 제공 하 여 코드 예제의 만들어집니다 개체는 ListViewItem 개체입니다. 이러한 ImageList 개체에 추가 되는 LargeImageListSmallImageList 속성입니다. 이 예제에서는 만들기에서 다음 속성을 사용 합니다 ListView 제어:

코드를 a Form 에 추가하고 폼의 생성자 또는 다른 메서드에서 예제에서 만든 메서드를 호출해야 합니다. 이 예제에서는 이름이 MySmallImage1, 및 MySmallImage2``MyLargeImage1``MyLargeImage2 드라이브 C의 루트 디렉터리에 있어야 합니다.

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.
      // Width of -2 indicates auto-size.
      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.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.
    // Width of -2 indicates auto-size.
    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 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.
    ' Width of -2 indicates auto-size.
    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

설명

컨트롤은 ListView 항목 목록을 표시한다는 점과 비슷합니다 ListBox . 주요 차이점은 컨트롤이 ListView 사용자가 항목을 볼 수 있는 다양한 방법을 제공한다는 것입니다. 클래스는 ListViewItem 컨트롤에 표시되는 ListView 항목과 연결된 모양, 동작 및 데이터를 정의합니다. ListViewItem 개체는 ListView 4개의 다른 보기 중 하나에서 컨트롤에 표시될 수 있습니다. 항목은 세로 목록에서 크거나 작은 아이콘으로 표시하거나 작은 아이콘으로 표시할 수 있습니다. 항목에는 부모 항목과 관련된 정보가 포함된 하위 항목이 있을 수도 있습니다. 네 번째 보기 스타일인 세부 정보 보기를 사용하면 하위 항목에 표시되는 정보를 식별하는 데 사용할 수 있는 열 머리글이 있는 표에 항목과 하위 항목을 표시할 수 있습니다.

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

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

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

생성자

ListViewItem()

기본값을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(ListViewGroup)

ListViewItem 클래스의 새 인스턴스를 초기화하고 지정된 그룹에 할당합니다.

ListViewItem(ListViewItem+ListViewSubItem[], Int32)

항목 아이콘의 이미지 인덱스 위치와 ListViewItem 개체의 배열을 사용하여 ListViewItem.ListViewSubItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(ListViewItem+ListViewSubItem[], Int32, ListViewGroup)

항목 아이콘의 이미지 인덱스 위치와 ListViewItem 개체의 배열을 사용하여 ListViewItem.ListViewSubItem 클래스의 새 인스턴스를 초기화하고 해당 항목을 지정된 그룹에 할당합니다.

ListViewItem(ListViewItem+ListViewSubItem[], String)

지정된 하위 항목 및 이미지를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(ListViewItem+ListViewSubItem[], String, ListViewGroup)

지정된 하위 항목, 이미지 및 그룹을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(SerializationInfo, StreamingContext)

지정한 직렬화 정보와 스트리밍 컨텍스트를 포함하는 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String)

지정된 항목 텍스트를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String, Int32)

지정된 항목 텍스트와 항목 아이콘의 이미지 인덱스 위치를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String, Int32, ListViewGroup)

지정된 항목 텍스트와 항목 아이콘의 이미지 인덱스 위치를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화하고 지정된 그룹에 항목을 할당합니다.

ListViewItem(String, ListViewGroup)

지정된 항목 텍스트를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화하고 지정된 그룹에 할당합니다.

ListViewItem(String, String)

지정된 텍스트 및 이미지를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String, String, ListViewGroup)

지정된 텍스트, 이미지 및 그룹을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[])

하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], Int32)

항목 아이콘의 이미지 인덱스 위치와 하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], Int32, Color, Color, Font)

항목 아이콘의 이미지 인덱스 위치, 전경색, 배경색, 항목의 글꼴과 하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], Int32, Color, Color, Font, ListViewGroup)

항목 아이콘의 이미지 인덱스 위치, 전경색, 배경색, 항목의 글꼴과 하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다. 지정된 그룹에 항목을 할당합니다.

ListViewItem(String[], Int32, ListViewGroup)

항목 아이콘의 이미지 인덱스 위치와 하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화하고 해당 항목을 지정된 그룹에 할당합니다.

ListViewItem(String[], ListViewGroup)

하위 항목을 나타내는 문자열 배열을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화하고 해당 항목을 지정된 그룹에 할당합니다.

ListViewItem(String[], String)

지정된 항목, 하위 항목 텍스트 및 이미지를 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], String, Color, Color, Font)

지정된 텍스트, 이미지, 색 및 글꼴이 들어 있는 하위 항목을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], String, Color, Color, Font, ListViewGroup)

지정된 텍스트, 이미지, 색, 글꼴 및 그룹이 들어 있는 하위 항목을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

ListViewItem(String[], String, ListViewGroup)

지정된 텍스트, 이미지 및 그룹이 들어 있는 하위 항목을 사용하여 ListViewItem 클래스의 새 인스턴스를 초기화합니다.

속성

BackColor

항목 텍스트의 배경색을 가져오거나 설정합니다.

Bounds

하위 항목을 포함하여 항목의 경계 사각형을 가져옵니다.

Checked

항목의 확인란이 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

Focused

ListView 컨트롤 내에서 항목에 포커스가 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

Font

항목에 표시되는 텍스트 글꼴을 가져오거나 설정합니다.

ForeColor

항목 텍스트의 전경색을 가져오거나 설정합니다.

Group

항목을 할당할 그룹을 가져오거나 설정합니다.

ImageIndex

항목에 표시되는 이미지의 인덱스를 가져오거나 설정합니다.

ImageKey

항목에 표시되는 이미지의 키를 가져오거나 설정합니다.

ImageList

항목과 함께 표시되는 이미지가 들어 있는 ImageList를 가져옵니다.

IndentCount

ListViewItem을 들여쓰는 데 사용할 작은 이미지 너비 값을 가져오거나 설정합니다.

Index

ListView 컨트롤에 포함된 항목의 인덱스(0부터 시작)를 가져옵니다.

ListView

항목이 포함된 ListView 컨트롤을 가져옵니다.

Name

ListViewItem과 관련된 이름을 가져오거나 설정합니다.

Position

ListViewItem의 왼쪽 맨 위 위치를 가져오거나 설정합니다.

Selected

항목이 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

StateImageIndex

항목에 대해 표시되는 상태 이미지의 인덱스를 가져오거나 설정합니다. 상태 이미지는 선택된 확인란이나 선택이 취소된 확인란처럼 항목의 상태를 나타내는 이미지입니다.

SubItems

항목의 모든 하위 항목이 포함된 컬렉션을 가져옵니다.

Tag

항목에 연결할 데이터가 포함된 개체를 가져오거나 설정합니다.

Text

항목 텍스트를 가져오거나 설정합니다.

ToolTipText

마우스 포인터가 ListViewItem을 가리킬 때 표시되는 텍스트를 가져오거나 설정합니다.

UseItemStyleForSubItems

항목에 대한 Font, ForeColorBackColor 속성을 해당 항목의 모든 하위 항목에 대해 사용할 것인지를 나타내는 값을 가져오거나 설정합니다.

메서드

BeginEdit()

항목 텍스트를 편집 모드로 설정합니다.

Clone()

항목의 동일 복사본을 만듭니다.

Deserialize(SerializationInfo, StreamingContext)

항목을 역직렬화합니다.

EnsureVisible()

필요한 경우 컨트롤의 내용을 스크롤하여 항목이 컨트롤에 표시되도록 만듭니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
FindNearestItem(SearchDirectionHint)

지정된 방향으로 검색하여 ListViewItem에서 다음 항목을 찾습니다.

GetBounds(ItemBoundsPortion)

항목에 대한 경계 사각형의 지정된 부분을 읽어 들입니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetSubItemAt(Int32, Int32)

지정된 좌표에 있는 ListViewItem의 하위 항목을 반환합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Remove()

연결된 ListView 컨트롤에서 해당 항목을 제거합니다.

Serialize(SerializationInfo, StreamingContext)

항목을 serialize합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

명시적 인터페이스 구현

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

항목을 serialize합니다.

적용 대상

추가 정보