ListViewItem.Tag Propriété
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit un objet qui contient les données à associer à l'élément.
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
Valeur de propriété
Objet qui contient des informations associées à l'élément.
- Attributs
Exemples
L’exemple de code suivant montre comment initialiser un ListViewItem et définir les Tag propriétés et Text . Pour exécuter cet exemple, placez le code suivant dans un formulaire qui contient un ListView nommé ListView1
et appelez InitializeListViewItems
à partir du constructeur ou Load de la méthode de gestion des événements du formulaire.
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
Remarques
La Tag propriété peut être utilisée pour stocker n’importe quel objet que vous souhaitez associer à un élément. Bien que vous puissiez stocker n’importe quel élément, la Tag propriété est généralement utilisée pour stocker des informations de chaîne sur l’élément, telles qu’un identificateur unique ou la position d’index des données de l’élément dans une base de données.
S’applique à
Commentaires
https://aka.ms/ContentUserFeedback.
Bientôt disponible : Tout au long de l’année 2024, nous abandonnerons progressivement le mécanisme de retour d’information GitHub Issues pour le remplacer par un nouveau système de commentaires. Pour plus d’informations, consultez :Soumettre et afficher des commentaires pour