简体   繁体   English

WPF列表视图中的字符串数字排序

[英]string numbers sorting in WPF listview

This code has some small issue 这段代码有一些小问题

listView1.Items.SortDescriptions.Add(new SortDescription("id",
        ListSortDirection.Ascending)); 

Sorts this string numbers: 22,20,3,5,8,10,12,14,17,2,1 into: 1,12,14,17,2,20,22,3,5,8 将此字符串编号排序:22,20,3,5,8,10,12,14,17,2,1成:1,12,14,17,2,20,22,3,5,8

Could anybody share an idea how to make a "normal" sorting? 任何人都可以分享一个如何进行“正常”排序的想法吗?

Is your id column an integer or string type? 您的id列是整数还是字符串类型? If it's a string type, the listview is sorting the strings correctly. 如果它是字符串类型,listview正在正确排序字符串。 In a nutshell, it checks each character of each string from left to right. 简而言之,它从左到右检查每个字符串的每个字符。

If you change the id column to an integer type, it will sort them the way you expect. 如果将id列更改为整数类型,它将按照您期望的方式对它们进行排序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM