Freigeben über


ListViewItem.Tag-Eigenschaft

Ruft das Objekt ab, das dem Element zuzuordnende Daten enthält, oder legt dieses fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<LocalizableAttribute(False)> _
<BindableAttribute(True)> _
Public Property Tag As Object
'Usage
Dim instance As ListViewItem
Dim value As Object

value = instance.Tag

instance.Tag = value
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public Object Tag { get; set; }
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public:
property Object^ Tag {
    Object^ get ();
    void set (Object^ value);
}
/** @property */
public Object get_Tag ()

/** @property */
public void set_Tag (Object value)
public function get Tag () : Object

public function set Tag (value : Object)

Eigenschaftenwert

Ein Objekt, das dem Element zugeordnete Informationen enthält.

Hinweise

Die Tag-Eigenschaft kann zur Speicherung jedes beliebigen Objekts verwendet werden, das Sie einem Element zuordnen möchten. Obwohl jedes Element gespeichert werden kann, wird die Tag-Eigenschaft normalerweise zur Speicherung von Zeichenfolgeninformationen des Elements verwendet, z. B. ein eindeutiger Bezeichner oder die Indexposition der Elementdaten in einer Datenbank.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie ein ListViewItem initialisiert wird und wie die Tag-Eigenschaft und die Text-Eigenschaft festgelegt werden. Wenn Sie dieses Beispiel ausführen möchten, fügen Sie folgenden Code in ein Formular ein, das die ListViewListView1 enthält, und rufen Sie InitializeListViewItems aus dem Konstruktor oder in der Load-Ereignisbehandlungsmethode des Formulars auf.

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
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:
   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.set_View(View.List);

    Cursor favoriteCursors[] = new Cursor[] { Cursors.get_Help(),
        Cursors.get_Hand(), Cursors.get_No(), Cursors.get_Cross() };
    // Populate the ListView control with the array of Cursors.
    for (int iCtr = 0; iCtr < favoriteCursors.length; iCtr++) {
        Cursor aCursor = favoriteCursors[iCtr];
        // Construct the ListViewItem object
        ListViewItem item = new ListViewItem();
        // Set the Text property to the cursor name.
        item.set_Text(aCursor.ToString());
        // Set the Tag property to the cursor.
        item.set_Tag(aCursor);
        // Add the ListViewItem to the ListView.
        listView1.get_Items().Add(item);
    }
} //InitializeListViewItems

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0

Siehe auch

Referenz

ListViewItem-Klasse
ListViewItem-Member
System.Windows.Forms-Namespace