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);
});
}
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);
See my other reply, it’s the decimal difference that is truncated.
Please login first to submit.