2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[.NET5 / Windows Forms] System.Windows.Forms.ListView の強化された機能を確認

Last updated at Posted at 2021-05-07

前置き

.NET 5 で「System.Windows.Forms.ListView」に新機能が追加されたようです。

  • System.Windows.Forms.ListView
  • 折りたたみ可能なグループをサポート
  • フッター
  • 字幕、タスク、およびタイトルの画像をグループ化

とのことで日本語訳だとなんのこっちゃだったのですが、これらすべて ListView の Group 機能に関するものでした。

折りたたみ可能なグループをサポート

ListViewGroup.CollapsedState を指定することで、グループを折りたたみ可能にすることができます。
Collapsedを指定すると折りたたまれた状態で表示。
Expandedを指定すると展開された状態で表示されます。

フッター

ListViewGroup.Footer に、文字列でグループごとのフッターを指定できます。
FooterAlignmentで水平方向の位置も指定できます。

字幕、タスク、およびタイトルの画像をグループ化

字幕 = サブタイトル

Listviewgroup.Subtitleに、文字列でグループごとのサブタイトルを指定できます。

タスク = タスクリンク

Listviewgroup.Tasklinkを設定することで、グループごとにリンクを表示させることができます。
このリンクをクリックするとListview.GroupTasklinkClickがトリガーされます。

画像 = グループのタイトルに画像を表示できる

ListViewGroup.TitleImageKey または ListViewGroup.TitleImageIndex を指定することで、グループのタイトルに画像を表示させることができます。
ここで指定するキーとインデックスですが、これは ListView.GroupImageList に対してのものになります。

ざっくりですが、以下使用例になります。

listview.PNG

            ImageList imageList = new ImageList();
            imageList.Images.Add("sample", Bitmap.FromFile(@"D:/\Users/\shima/\Pictures/\qiita-brand-color.PNG"));
            myListView.GroupImageList = imageList;

            myListView.GroupTaskLinkClick += MyListView_GroupTaskLinkClick;
            foreach (ListViewGroup listViewGroup in myListView.Groups)
            {
                listViewGroup.CollapsedState = ListViewGroupCollapsedState.Expanded;
                listViewGroup.Footer = $"「{listViewGroup.Header}」のフッター";
                listViewGroup.FooterAlignment = HorizontalAlignment.Center;
                listViewGroup.Subtitle = $"「{listViewGroup.Header}」のサブタイトル";
                listViewGroup.TitleImageKey = @"sample";
                listViewGroup.TaskLink = $"「{listViewGroup.Header}」のタスクリンク";
            }
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?