Skip to content

ListView column sort "Double" datatype #909

Closed

Description

@itg-assistant

conrad asked 2017-06-20 23:23:01 UTC

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

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-06-20 23:27:59 UTC

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

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions