ListViewGroupCollection.Clear メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ListViewGroupCollection.Clear メソッドの意味・解説 

ListViewGroupCollection.Clear メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

コレクションからすべてのグループ削除します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

詳細ビューサブ項目の値を使って ListView 項目を整理するアプリケーションで、Clear メソッド使用する方法次の例に示します。この形式グループ化は、Windows エクスプローラ使用されているグループ化似てます。この例では、グループ動的に作成されます。サブ項目列では、一意サブ項目値ごとに 1 つグループ作成されます。親項目列では、一意先頭文字ごとに 1 つグループ作成されます。各列について作成されグループは、サブ項目のテキストまたは先頭文字と共にハッシュ テーブル格納されます。ヘッダークリックされると、ListViewGroupCollection がクリアされます次にクリックされた列に対応するハッシュ テーブル取得され、各項目が適切なグループ割り当てられます。最後に並べ替えられたハッシュ テーブル内のグループ配列ListViewGroupCollection追加されます。

コード全体については、ListViewGroupCollection概要リファレンス トピック参照してください

' 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ListViewGroupCollection クラス
ListViewGroupCollection メンバ
System.Windows.Forms 名前空間


このページでは「.NET Framework クラス ライブラリ リファレンス」からListViewGroupCollection.Clear メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からListViewGroupCollection.Clear メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からListViewGroupCollection.Clear メソッド を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ListViewGroupCollection.Clear メソッド」の関連用語

ListViewGroupCollection.Clear メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ListViewGroupCollection.Clear メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS