ListViewItem.Tag プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
項目に関連付けられているデータを含むオブジェクトを取得または設定します。
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し、 プロパティと Text プロパティを設定する方法をTag示します。 この例を実行するには、 という名前ListView1
の を含むフォームに次のコードをListView配置し、フォームのコンストラクターまたはLoadイベント処理メソッドから を呼び出InitializeListViewItems
します。
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 一意識別子や、データベース内のアイテムのデータのインデックス位置など、アイテムに関する文字列情報を格納するために使用されます。
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET