问题描述
我有这样的一个列表框:
测试| 10
名称| 44
布拉布拉| 16
和我想在年底(10 44 16),这些项目通过他们的数量进行排序,以使他们成为责令这样的:
名称| 44
布拉布拉| 16
测试| 10
看起来你实际上是在寻找降序排列。不管怎么说,这里是从一个列表解决另一个问题:
昏暗myList中作为列表(字符串)= {测试| 10,名称| 44,布拉布拉| 16}了ToList
昏暗orderedList方式列表(字符串)=(从项目在myList上顺序按item.Substring(item.IndexOf(|)+ 1)降序选择项).ToList
编辑:这将项目作为字符串进行排序,这意味着如果你有44,16,100,10,它看起来像这样进行排序后:44,16,100,10,这可能不是什么你想要的,所以你应该分析该号码的开出成整数,让他们排序数字。试试这个:
昏暗myList中作为列表(字符串)= {测试| 10,名称| 44,布拉布拉| 16,富| 100}了ToList
昏暗orderedList方式列表(字符串)=(从项目在myList上顺序按Integer.Parse(item.Substring(item.IndexOf(|)+ 1))降序选择项).ToList
I have a listbox with something like this:
test|10
name|44
blabla|16
and I want sort those items by the number they have at the end (10 44 16), such that they become ordered like this:
name|44
blabla|16
test|10
It looks like you are actually looking for descending order. Anyways, here is a solution from one list to another:
Dim myList As List(Of String) = {"test|10", "name|44", "blabla|16"}.ToList
Dim orderedList As List(Of String) = (From item In myList Order By item.Substring(item.IndexOf("|") + 1) Descending Select item).ToList
EDIT: This will sort the items as strings, which means that if you have 44, 16, 100, and 10, it would look like this after being sorted: 44, 16, 100, 10. This is probably not what you want, so you should parse the numbers out into integers so that they sort numerically. Try this:
Dim myList As List(Of String) = {"test|10", "name|44", "blabla|16", "foo|100"}.ToList
Dim orderedList As List(Of String) = (From item In myList Order By Integer.Parse(item.Substring(item.IndexOf("|") + 1)) Descending Select item).ToList
这篇关于如何排序列表框与字母和数字上升的用数字vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!