2013-02-15 49 views
-1

我們有WPF應用程序,其中我們是ListView的一種形式, 我們希望以字母數字順序排列項目。在WPF中的列表視圖中對列中的Alpha進行數列排序

當我們需要排序字母數字EG

AW1 AW2 AW3

目前,它是排序的列進行排序

AW1 AW100 AW2 AW200

那麼需要改變什麼?

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

而且

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

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

排序功能這個樣子,

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(); 
    } 
+0

我不知道如何檢查字母數字,請幫助。 – 2013-02-15 12:38:11

回答

0

字符串比較是通過人物從左至右做字符。因此,如果您將列名更改爲AW001,AW100,AW002,AW200您的排序將工作得很好。