はい、私は同様の動作を見てきました。私が従った解決策はコードhereに基づいています。
実際にリストビューに項目を追加するコードで
public partial class ListViewExtended : ListView
{
private Collection<Dictionary<string, ListViewGroup>> groupTables = new Collection<Dictionary<string,ListViewGroup>>();
public ListViewExtended()
{
InitializeComponent();
}
/// <summary>
/// Create groups for each column of the list view.
/// </summary>
public void CreateGroups()
{
CreateGroups(false);
}
/// <summary>
/// Create groups for each column of the list view.
/// </summary>
public void CreateGroups(bool reset)
{
if (OSFeature.Feature.IsPresent(OSFeature.Themes))
{
if (reset)
{
this.groupTables.Clear();
}
for (int column = 0; column < this.Columns.Count; column++)
{
Dictionary<string, ListViewGroup> groups = new Dictionary<string, ListViewGroup>();
foreach (ListViewItem item in this.Items)
{
string subItemText = item.SubItems[column].Text;
// Use the initial letter instead if it is the first column.
if (column == 0)
{
subItemText = subItemText.Substring(0, 1).ToUpperInvariant();
}
if (!groups.ContainsKey(subItemText))
{
groups.Add(subItemText, new ListViewGroup(subItemText) { Name = subItemText });
}
}
this.groupTables.Add(groups);
}
}
}
/// <summary>
/// Sets the list view to the groups created for the specified column.
/// </summary>
/// <param name="column"></param>
public void SetGroups(int column)
{
if (OSFeature.Feature.IsPresent(OSFeature.Themes))
{
try
{
this.BeginUpdate();
this.Groups.Clear();
if (column == -1)
{
this.ShowGroups = false;
}
else
{
this.ShowGroups = true;
Dictionary<string, ListViewGroup> groups = groupTables[column];
this.Groups.AddRange(groups.Values.OrderBy(g => g.Name).ToArray());
foreach (ListViewItem item in this.Items)
{
string subItemText = item.SubItems[column].Text;
// For the Title column, use only the first letter.
if (column == 0)
{
subItemText = subItemText.Substring(0, 1).ToUpperInvariant();
}
item.Group = groups[subItemText];
}
groups.Values.ForEach<ListViewGroup>(g => g.Header = String.Format(CultureInfo.CurrentUICulture, "{0} ({1})", g.Name, g.Items.Count));
}
}
finally
{
this.EndUpdate();
}
}
}
}
、あなたはこのような何かをしたい:
this.itemsListView.Items.AddRange(items.ToArray());
this.itemsListView.CreateGroups(true);
this.itemsListView.SetGroups(0); // Group by the first column by default.
が、これは予測可能な方法で発生しますか?具体的には、アイテムの特定のテストセットが与えられた場合、常に「デフォルト」グループにダンプされるのは同じアイテムですか?あなたがそのテストセットからアイテムを徐々に削除すると、(まだそこにあるアイテムの)同じアイテムが「デフォルト」にダンプされるのでしょうか、それとも別のアイテムにダンプされますか? – itowlson
はい。パターンを取得したら、それを再現するのは簡単です。 –
私はコードが再現するには大きすぎると認識していますが、振る舞いが再現可能であれば、テストセットに2つの項目があり、そのうちの1つが正しくグループ化され、そのうちの1つがグループ化されません。もしそうなら、グループを追加し、各項目のGroupプロパティを設定するコードと共に、これら2つの項目を投稿できますか?あるいは、「一度パターンを取得すると再現しやすい」と言います。これは、誤ったグループ分けのパターンを特定したことを意味しますか?あなたはそのパターンを記述できますか? – itowlson