在ListBox中对项目进行排序 [英] Sort Items in ListBox

查看:84
本文介绍了在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 the Sort property of the ListBox control.

If that does not satisfy your needs, you can use the ListView control instead of the ListBox control. With the ListView control, use the ListViewItemSorter property to specify an IComparer function to do the sort compare on whatever keys you code into the IComparer 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆