Click here to Skip to main content
15,860,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
Posted

Hi,

Use the ListBox.Sort Method[^]
 
Share this answer
 
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.
 
Share this answer
 
Try this may be it helps

C#
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()));
       }
 
Share this answer
 
Comments
nareshkumar464 3-Aug-13 3:18am    
Hi thanks for the reply...but the code is not sorting according to my requirement.I want to sort the items based on first 3 values(i.e., 1237,1,1 & 1223,2,2 etc... in input) in ascending order.
can u please suggest me another logic.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900