ListViewItem.Group プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As ListViewItem Dim value As ListViewGroup value = instance.Group instance.Group = value
[LocalizableAttribute(true)] public: property ListViewGroup^ Group { ListViewGroup^ get (); void set (ListViewGroup^ value); }
/** @property */ public ListViewGroup get_Group () /** @property */ public void set_Group (ListViewGroup value)
項目の割り当て先の ListViewGroup。

このプロパティは、項目の所属先グループを設定するために使用します。ListViewItem コンストラクタでもグループを設定できますが、このプロパティを使用すると、実行時にグループのメンバシップを変更できます。ListView.Groups コレクション内にグループが存在する場合に、このプロパティを null 参照 (Visual Basic では Nothing) に設定すると、"DefaultGroupSystem.Windows.Forms" というヘッダー ラベルを持つ既定のグループに項目が割り当てられます。既定のグループは ListView.Groups コレクションに格納されていないため、変更できません。特に、デバッグですべての項目がグループに適切に追加されていることを確認する際に有効です。
![]() |
---|
ListView グループは、Windows XP および Windows Server 2003 ファミリ (Windows XP Home Edition、Windows XP Professional、Windows Server 2003) でだけ使用できます。詳細については、ListViewGroup の概要のトピックを参照してください。 |

詳細ビューのサブ項目の値を使って ListView 項目を整理するアプリケーションで、Group プロパティを使用する方法を次のコード例に示します。この形式のグループ化は、Windows エクスプローラで使用されているグループ化と似ています。この例では、グループが動的に作成されます。各サブ項目列では、一意のサブ項目値ごとに 1 つのグループが作成されます。親項目列では、一意の先頭の文字ごとに 1 つのグループが作成されます。各列について作成されたグループは、サブ項目のテキストまたは先頭の文字と共にハッシュ テーブルに格納されます。列ヘッダーがクリックされると、その列に対応するハッシュ テーブルが取得されます。次に、その列のサブ項目テキストの値がハッシュ テーブルのキーとして使用されて、各項目の正確なグループが取得されます。次に、Group プロパティを使用して、その項目がグループに割り当てられます。
このコード例は ListView.Groups プロパティの例の "一部" です。
' Sets myListView to the groups created for the specified column. Private Sub SetGroups(column As Integer) ' Remove the current groups. myListView.Groups.Clear() ' Retrieve the hash table corresponding to the column. Dim groups As Hashtable = CType(groupTables(column), Hashtable) ' Copy the groups for the column to an array. Dim groupsArray(groups.Count - 1) As ListViewGroup groups.Values.CopyTo(groupsArray, 0) ' Sort the groups and add them to myListView. Array.Sort(groupsArray, New ListViewGroupSorter(myListView.Sorting)) myListView.Groups.AddRange(groupsArray) ' Iterate through the items in myListView, assigning each ' one to the appropriate group. Dim item As ListViewItem For Each item In myListView.Items ' Retrieve the subitem text corresponding to the column. Dim subItemText As String = item.SubItems(column).Text ' For the Title column, use only the first letter. If column = 0 Then subItemText = subItemText.Substring(0, 1) End If ' Assign the item to the matching group. item.Group = CType(groups(subItemText), ListViewGroup) Next item End Sub 'SetGroups
// Sets myListView to the groups created for the specified column. private void SetGroups(int column) { // Remove the current groups. myListView.Groups.Clear(); // Retrieve the hash table corresponding to the column. Hashtable groups = (Hashtable)groupTables[column]; // Copy the groups for the column to an array. ListViewGroup[] groupsArray = new ListViewGroup[groups.Count]; groups.Values.CopyTo(groupsArray, 0); // Sort the groups and add them to myListView. Array.Sort(groupsArray, new ListViewGroupSorter(myListView.Sorting)); myListView.Groups.AddRange(groupsArray); // Iterate through the items in myListView, assigning each // one to the appropriate group. foreach (ListViewItem item in myListView.Items) { // Retrieve the subitem text corresponding to the column. string subItemText = item.SubItems[column].Text; // For the Title column, use only the first letter. if (column == 0) { subItemText = subItemText.Substring(0, 1); } // Assign the item to the matching group. item.Group = (ListViewGroup)groups[subItemText]; } }
// Sets myListView to the groups created for the specified column. private: void SetGroups(int column) { // Remove the current groups. myListView->Groups->Clear(); // Retrieve the hash table corresponding to the column. Hashtable^ groups = dynamic_cast<Hashtable^>(groupTables[column]); // Copy the groups for the column to an array. array<ListViewGroup^>^ groupsArray = gcnew array<ListViewGroup^>(groups->Count); groups->Values->CopyTo(groupsArray, 0); // Sort the groups and add them to myListView. Array::Sort(groupsArray, gcnew ListViewGroupSorter(myListView->Sorting)); myListView->Groups->AddRange(groupsArray); // Iterate through the items in myListView, assigning each // one to the appropriate group. IEnumerator^ myEnum = myListView->Items->GetEnumerator(); while (myEnum->MoveNext()) { ListViewItem^ item = safe_cast<ListViewItem^>(myEnum->Current); // Retrieve the subitem text corresponding to the column. String^ subItemText = item->SubItems[column]->Text; // For the Title column, use only the first letter. if (column == 0) { subItemText = subItemText->Substring(0, 1); } // Assign the item to the matching group. item->Group = dynamic_cast<ListViewGroup^>(groups[subItemText]); } }
// Sets myListView to the groups created for the specified column. private void SetGroups(int column) { // Remove the current groups. myListView.get_Groups().Clear(); // Retrieve the hash table corresponding to the column. Hashtable groups = (Hashtable)groupTables.get_Item(column); // Iterate through the items in myListView, assigning each // one to the appropriate group. for (int iCtr = 0; iCtr < myListView.get_Items().get_Count(); iCtr++) { ListViewItem item = myListView.get_Items().get_Item(iCtr); // Retrieve the subitem text corresponding to the column. String subItemText = item.get_SubItems().get_Item(column).get_Text(); // For the Title column, use only the first letter. if (column == 0) { subItemText = subItemText.Substring(0, 1); } // Assign the item to the matching group. item.set_Group((ListViewGroup)(groups.get_Item(subItemText))); } // Copy the groups for the column to an array. ListViewGroup groupsArray[] = new ListViewGroup[groups.get_Count()]; groups.get_Values().CopyTo(groupsArray, 0); // Sort the groups and add them to myListView. Array.Sort(groupsArray, new ListViewGroupSorter( myListView.get_Sorting())); myListView.get_Groups().AddRange(groupsArray); } //SetGroups

Windows 98, Windows 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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からListViewItem.Group プロパティを検索する場合は、下記のリンクをクリックしてください。

- ListViewItem.Group プロパティのページへのリンク