ListView column sort "Double" datatype

0
0

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);
});
}

  • You must to post comments
0
0

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);

  • You must to post comments
0
0

See my other reply, it’s the decimal difference that is truncated.

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.