You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to add another datatype for column sorting in the listview but something is not right in this expression? It works for "Int32" datatype but not for "Double" (I have both positive and negative numbers in one column)
else if (dataType == typeof(Int32))
{
listView.Sort((x, y) =>
{
return direction * Int32.Parse(x.SubItems[column.Index].Text) - Int32.Parse(y.SubItems[column.Index].Text);
});
}
else if (dataType == typeof(Double))
{
listView.Sort((x, y) =>
{
return direction * Double.Parse(x.SubItems[column.Index].Text) - Double.Parse(y.SubItems[column.Index].Text);
});
}
Activity
itg-assistant commentedon Jun 12, 2026
Luca answered 2017-06-20 23:27:59 UTC
See my other reply, it's the decimal difference that is truncated.
itg-assistant commentedon Jun 12, 2026
conrad answered 2017-06-21 14:40:23 UTC
Excellent, that worked. Thank you!
var diff = Double.Parse(x.SubItems[column.Index].Text) – Double.Parse(y.SubItems[column.Index].Text);
return direction * (diff < 0 ? -1 : diff > 0 ? 1 : 0);