在ListBox中对项目进行排序 [英] Sort Items in ListBox
问题描述
目前Iam使用框架2.0。在那里,我有一个列表框,项目如下
我想要排序如下项目。
输入:
1237,1,1,2,\\192.168.1.198 \volume2 \\ \\ 1237_1_1.mp4,2.4.5,2.15.1
1223,2,2,2,\\192.168.1.198 \volume2 \1223_2_2.mp4,2.4.5,2.15。 1
1237,1,2,2,\\192.168.1.198 \volume2 \\\ t1237_1_2.mp4,2.4.5,2.15.1
1223, 2,1,2,\\192.168.1.198 \volume2 \\\1223_1_3.mp4,2.4.5,2.15.1
1237,1,3,2,\\\\ 192.168 .1.198\volume2\1237_1_3.mp4,2.4.5,2.15.1
OutPut:
1223,2,1, 2,\\192.168.1.198 \volume2 \\\1223_2_1.mp4,2.4.5,2.15.1
1223,2,2,2,\\192.168.1.198 \ volume2 \1223_2_2.mp4,2.4.5,2.15.1
1237,1,1,2,\\192.168.1.198 \volume2 \\\ 1237_1_1.mp4,2.4.5, 2.15.1
1237,1,2,2,\\192.168.1.19 8\volume2\1237_1_2.mp4,2.4.5,2.15.1
1237,1,3,2,\\192.168.1.198 \volume2 \\\ 1237_1_3.mp4,2.4 .5,2.15.1
任何人都可以建议我,该怎么办?
(我必须按升序排序前3个值说:1223,2,1)
Hi,
Currently Iam using framework 2.0.In that,i have a listbox and items are as follows
I want to sort the below items.
input:
1237,1,1,2,\\192.168.1.198\volume2\1237_1_1.mp4,2.4.5,2.15.1
1223,2,2,2,\\192.168.1.198\volume2\1223_2_2.mp4,2.4.5,2.15.1
1237,1,2,2,\\192.168.1.198\volume2\1237_1_2.mp4,2.4.5,2.15.1
1223,2,1,2,\\192.168.1.198\volume2\1223_1_3.mp4,2.4.5,2.15.1
1237,1,3,2,\\192.168.1.198\volume2\1237_1_3.mp4,2.4.5,2.15.1
OutPut:
1223,2,1,2,\\192.168.1.198\volume2\1223_2_1.mp4,2.4.5,2.15.1
1223,2,2,2,\\192.168.1.198\volume2\1223_2_2.mp4,2.4.5,2.15.1
1237,1,1,2,\\192.168.1.198\volume2\1237_1_1.mp4,2.4.5,2.15.1
1237,1,2,2,\\192.168.1.198\volume2\1237_1_2.mp4,2.4.5,2.15.1
1237,1,3,2,\\192.168.1.198\volume2\1237_1_3.mp4,2.4.5,2.15.1
can anyone suggest me,what to do?
(I have to sort first 3 values in ascending order say:1223,2,1)
推荐答案
使用ListBox.Sort方法 [ ^ ]
您可以使用ListBox的
控制。Sort
属性
如果这不能满足您的需求,您可以使用ListView
控件而不是ListBox
控制。使用ListView
控件,使用ListViewItemSorter
属性指定IComparer
函数对你在IComparer
函数中编码的任何键进行排序比较。您可以连接多个列以形成比较密钥。
请参阅ListView.ListViewItemSorter Property [ ^ ]示例。
You can use theSort
property of theListBox
control.
If that does not satisfy your needs, you can use theListView
control instead of theListBox
control. With theListView
control, use theListViewItemSorter
property to specify anIComparer
function to do the sort compare on whatever keys you code into theIComparer
function. You can concatenate several columns to form a key for the compare.
See ListView.ListViewItemSorter Property[^] for an example.
尝试这可能有帮助
Try this may be it helps
System.Collections.SortedList asd = new SortedList();
foreach (ListItem ll in ListBox1.Items)
{
asd.Add(ll.Text, ll.Value);
}
ListBox1.Items.Clear();
foreach (String key in asd.Keys)
{
ListBox1.Items.Add(new ListItem(key, asd[key].ToString()));
}
这篇关于在ListBox中对项目进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!