-1

We have WPF application, In which we are ListView in One form, We want to order item alphanumerically.

When we sort the columns it needs to sort alpha numerical EG

AW1 AW2 AW3

At the moment it is sorting

AW1 AW100 AW2 AW200

So what need to be changed?

 if (lastDirection == ListSortDirection.Ascending)
                    {
                        direction = ListSortDirection.Descending;
                    }
                    else
                    {
                        direction = ListSortDirection.Ascending;
                    }

And

   // get the sort property name from the column's information.
                string sortPropertyName = sortableGridViewColumn.SortPropertyName;

                // Sort the data.
                Sort(sortPropertyName, direction);

SORT function like this,

private void Sort(string sortBy, ListSortDirection direction)
    {
        lastDirection = direction;
        ICollectionView dataView = CollectionViewSource.GetDefaultView(this.ItemsSource);

        dataView.SortDescriptions.Clear();
        SortDescription sd = new SortDescription(sortBy, direction);

        dataView.SortDescriptions.Add(sd);
        dataView.Refresh();
    }
Constant Learner
  • 525
  • 4
  • 13
  • 30

1 Answers1

0

String comparison is done character by character from left to right. So if you change your column names to AW001, AW100, AW002, AW200 your sorting will work just fine.

TrueEddie
  • 2,183
  • 2
  • 26
  • 36