ListViewItem.Tag Property

Gets or sets an object that contains data to associate with the item.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

<TypeConverterAttribute(GetType(StringConverter))> _
<LocalizableAttribute(False)> _
<BindableAttribute(True)> _
Public Property Tag As Object
Dim instance As ListViewItem
Dim value As Object

value = instance.Tag

instance.Tag = value
/** @property */
public Object get_Tag ()

/** @property */
public void set_Tag (Object value)

public function get Tag () : Object

public function set Tag (value : Object)

Not applicable.

Property Value

An object that contains information that is associated with the item.

The Tag property can be used to store any object that you want to associate with an item. Although you can store any item, the Tag property is typically used to store string information about the item, such as a unique identifier or the index position of the item's data in a database.

The following code example demonstrates how to initialize a ListViewItem and set the Tag and Text properties. To run this example, place the following code in a form that contains a ListView named ListView1, and call InitializeListViewItems from the form's constructor or Load event-handling method.

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.
End Sub

private void InitializeListViewItems()

    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.
        // Set the Tag property to the cursor.
        // Add the ListViewItem to the ListView.
} //InitializeListViewItems

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0