I have a ListView
and I am trying to sort them where items with a BackColor
of red would be first, and then items with a ForeColor
of red, and lastly the rest of the items, but all of them should be sorted by name within their group.
I wrote this code but I still get chunks of same items separated all over:
public int Compare (object x, object y)
{
int CompareResult;
ListViewItem a = (ListViewItem) x;
ListViewItem b = (ListViewItem) y;
if (a.BackColor == Color.FromArgb (200, 0, 0))
{
if (b.BackColor == Color.FromArgb(200, 0, 0))
{
return a.Text.CompareTo(b.Text);
}
else
{
return -1;
}
}
else
{
if (a.ForeColor == Color.FromArgb(200, 0, 0))
{
if (b.ForeColor == Color.FromArgb(200, 0, 0))
{
return a.Text.CompareTo(b.Text);
}
else
{
return -1;
}
}
else
{
return 1;
}
}
}