0

少し論理的な助けが必要です: リストビュー項目のコレクションがあり、そのカテゴリ (listviewitem.tag.tostring()) に従ってさまざまなグループに分類する必要があります。たとえば: リストビューに 10 個の項目があり、そのタグは「食品」です。野菜「飲み物」などのタグがついた商品をまとめて欲しいです。

前もって感謝します

4

2 に答える 2

0

ObjectListView (標準の .NET ListView のオープン ソース ラッパー)を使用すると、ListView を使用した作業がはるかに簡単になります。

たとえば、グループ化を有効にするのは 1 行で、各行がどのグループに属しているかをコントロールに伝えます。

lastPlayedColumn.GroupKeyGetter = delegate(object rowObject) { 
    Song song = (Song)rowObject; 
    return new DateTime(song.LastPlayed.Year, song.LastPlayed.Month, 1); 
};

これにより、次のようになります。

グループを含む ObjectListView
(出典: sourceforge.net )

もう少し作業を加えるだけで、次のような凝ったものを作成できます。

凝ったグループを持つ ObjectListView
(出典: sourceforge.net )

于 2013-09-02T02:15:52.860 に答える
0

を使用しDictionary<string,List<ListViewItem>>てグループを保存できますKey。 はグループ キーでfoodvegetables、 、drinks、... (カテゴリ名) にすることができます。対応するカテゴリのアイテムのValueリストです。

var groups = listView1.Items.OfType<ListViewItem>()
                      .GroupBy(e=>e.Tag.ToString())
                      .ToDictionary(k=>k.Key, v=>v.ToList());
//Then to access a category's items, just pass in the category name into the Dictionary like this
var food = groups["food"];//this is a List<ListViewItem> of items in the category 'food'
//try printing the items
foreach(var f in food)
   System.Diagnostics.Debug.Print(f.Text);
于 2013-08-31T09:07:21.973 に答える