ListView column sort "Double" datatype

Welcome to Wisej Support.
Questions, suggestions and plain old bugs - are all welcome here!
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
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Attachment
File Name Size
There are currently no files uploaded.
Maximum number of files 1, maximum file size 3.9MB.
Supported file formats: zip pdf gif jpg bmp png cs vb theme json