Displaying selected items at the top of the listbox

G

Guest

Displaying selected items at the top of the listbox

Hi,
I am having two listboxes - one with ids and second with the related names.
When user selects an item in one listbox, the corresponding item will be
selected in the second listbox too. The problem is, when the user selects an
item and it is in the middle of the list, the user is not able to know
whether it is selected or not. Is there a way to display all the selected
items (multiple selection is allowed) at the top of the listboxes? I am using
datasource to bind the data to the listboxes.
Thanks!!!!!!!!!
 
E

Elliot Rodriguez

Untested, but this should be the right direction:

For Each Thing as ListItem In ListOfThings.Items
If Thing.Selected Then
ListOfThings.Items.Insert(0, Thing)
End If
Next

Note that databinding and postbacks may affect how this is executed, so pay
attention to your page events. Also I'm not 100% sure offhand whether this
will create a new ListItem object and leave the other behind, or if it will
rearrange like you need (I think it will rearrange it).
 
G

Guest

'find the selected item in the second List
Dim LItem As ListItem = secondList.Items.FindByValue(ID)
If LItem Is Nothing Then
'add it at the very top
secondList.Items.Insert(0, New ListItem(LItem.Value, LItem.Text))
'remove the found item
secondList.Items.Remove(LItem)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top