ListViewItem.Tag 속성

정의

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

public:
 property System::Object ^ Tag { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object Tag { get; set; }
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))]
public object? Tag { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter))>]
member this.Tag : obj with get, set
Public Property Tag As Object

속성 값

항목에 연결할 정보가 포함된 개체입니다.

특성

예제

다음 코드 예제를 초기화 ListViewItem 하 고 설정 Tag 하는 방법을 보여 줍니다는 및 Text 속성입니다. 이 예제를 실행하려면 라는 가 포함된 ListView 폼에 다음 코드를 배치하고 폼의 생성자 또는 Load 이벤트 처리 메서드에서 를 호출 InitializeListViewItemsListView1합니다.

private:
   void InitializeListViewItems()
   {
      ListView1->View = View::List;
      array<System::Windows::Forms::Cursor^>^favoriteCursors = {Cursors::Help,Cursors::Hand,Cursors::No,Cursors::Cross};
      
      // Populate the ListView control with the array of Cursors.
      System::Collections::IEnumerator^ myEnum = favoriteCursors->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         System::Windows::Forms::Cursor^ aCursor = safe_cast<System::Windows::Forms::Cursor^>(myEnum->Current);
         
         // Construct the ListViewItem object
         ListViewItem^ item = gcnew ListViewItem;
         
         // Set the Text property to the cursor name.
         item->Text = aCursor->ToString();
         
         // Set the Tag property to the cursor.
         item->Tag = aCursor;
         
         // Add the ListViewItem to the ListView.
         ListView1->Items->Add( item );
      }
   }
private void InitializeListViewItems()
{
    ListView1.View = View.List;

    Cursor[] favoriteCursors = new Cursor[]{Cursors.Help, 
        Cursors.Hand, Cursors.No, Cursors.Cross};

    // Populate the ListView control with the array of Cursors.
    foreach ( Cursor aCursor in favoriteCursors )
    {

        // Construct the ListViewItem object
        ListViewItem item = new ListViewItem();

        // Set the Text property to the cursor name.
        item.Text = aCursor.ToString();

        // Set the Tag property to the cursor.
        item.Tag = aCursor;

        // Add the ListViewItem to the ListView.
        ListView1.Items.Add(item);
    }
}
Private Sub InitializeListViewItems()
    ListView1.View = View.List
    Dim aCursor As Cursor

    Dim favoriteCursors() As Cursor = New Cursor() _
                {Cursors.Help, Cursors.Hand, Cursors.No, Cursors.Cross}

    ' Populate the ListView control with the array of Cursors.
    For Each aCursor In favoriteCursors

        ' Construct the ListViewItem object
        Dim item As New ListViewItem

        ' Set the Text property to the cursor name.
        item.Text = aCursor.ToString

        ' Set the Tag property to the cursor.
        item.Tag = aCursor

        ' Add the ListViewItem to the ListView.
        ListView1.Items.Add(item)
    Next
End Sub

설명

속성은 Tag 항목과 연결하려는 모든 개체를 저장하는 데 사용할 수 있습니다. 항목을 Tag 저장할 수 있지만 속성은 일반적으로 항목에 대한 문자열 정보(예: 고유 식별자 또는 항목 데이터의 인덱스 위치)를 데이터베이스에 저장하는 데 사용됩니다.

적용 대상