items added in listbox sorted asc[modified]
-
Hello! I used this code, and it works to not allow duplicates: Dim li As New ListItem For Each li In LB1.Items If li.Selected = True Then If Not ListBox2.Items.Contains(li) Then ListBox2.Items.Add(li) End If End If Next After the items are added, my second goal is to sort them ASC too. Haven't quite figured that out as well. Any suggestions are appreciated. Thanks! -- modified at 9:57 Monday 7th August, 2006
-
Hello! I used this code, and it works to not allow duplicates: Dim li As New ListItem For Each li In LB1.Items If li.Selected = True Then If Not ListBox2.Items.Contains(li) Then ListBox2.Items.Add(li) End If End If Next After the items are added, my second goal is to sort them ASC too. Haven't quite figured that out as well. Any suggestions are appreciated. Thanks! -- modified at 9:57 Monday 7th August, 2006
I'm not exactly sure what it is you are trying to do here however to avoid duplicates you could insert the items into a hashtable and bind the listbox to it.
only two letters away from being an asset
-
I'm not exactly sure what it is you are trying to do here however to avoid duplicates you could insert the items into a hashtable and bind the listbox to it.
only two letters away from being an asset
-
Hello! I used this code, and it works to not allow duplicates: Dim li As New ListItem For Each li In LB1.Items If li.Selected = True Then If Not ListBox2.Items.Contains(li) Then ListBox2.Items.Add(li) End If End If Next After the items are added, my second goal is to sort them ASC too. Haven't quite figured that out as well. Any suggestions are appreciated. Thanks! -- modified at 9:57 Monday 7th August, 2006
-
Where do you get the items from? If you for an example get them from a database, it's easier and more efficient to remove duplicates and sort in the database query, than writing code for it.
--- b { font-weight: normal; }
Guffa, I get the items from a db call to populate the left listbox on my page. The user will click on this listbox to transfer the "number" over to the right side listbox, Listbox2, on the page. I'm trying this code to sort the items in Listbox2, but get: At least one object must implement IComparable. Dim items As New ArrayList(ListBox2.Items) items.Sort() ListBox2.DataSource = items
-
Guffa, I get the items from a db call to populate the left listbox on my page. The user will click on this listbox to transfer the "number" over to the right side listbox, Listbox2, on the page. I'm trying this code to sort the items in Listbox2, but get: At least one object must implement IComparable. Dim items As New ArrayList(ListBox2.Items) items.Sort() ListBox2.DataSource = items
Implement an IComparer for ListItem, and use that in the call to the Sort method. But, shouldn't you do this using client script instead? If you use server code to move the items, you will be sending a lot of data back and forth between the server and the client.
--- b { font-weight: normal; }
-
Implement an IComparer for ListItem, and use that in the call to the Sort method. But, shouldn't you do this using client script instead? If you use server code to move the items, you will be sending a lot of data back and forth between the server and the client.
--- b { font-weight: normal; }
Got it to work with this: http://www.411asp.net/func/content?tree=411asp/tutorial/specific/web/userinte/webcontr/listbox&id=5881410 Thanks to all for the help!