カスタム ソーター (ListCollectionView.CustomSort プロパティで設定) を備えたリスト ビューがありますが、リスト ビューの上部に新しい項目を挿入したいと考えています。CustomSort を抑制するにはどうすればよいですか?
ソートロジックを調整する考えがあるため、新しく追加されたアイテムが最初のアイテムになりますが、このソリューションは少し臭いです。
Why suppress CustomSort? Adapt it for your needs:
You could give all new items an extreme value for the property used in IComparer object for sorting, e.G. int.MaxValue or string.Empty.
Or create an additional property IsNew and include it into comparing process.
class MyClass
{
public bool IsNew { get; set; }
public string Name { get; set; }
}
class MyComparer : IComparer<MyClass>
{
public int Compare(MyClass x, MyClass y)
{
if (x.IsNew ^ y.IsNew)
{
return x.IsNew ? -1 : 1;
}
else
{
return StringComparer.InvariantCulture.Compare(x.Name, y.Name);
}
}
}