By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,496 Members | 1,489 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,496 IT Pros & Developers. It's quick & easy.

Displaying selected items at the top of the listbox

P: n/a
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!!!!!!!!!
Mar 9 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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).

"Srimadhi" <Sr******@discussions.microsoft.com> wrote in message
news:9A**********************************@microsof t.com...
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!!!!!!!!!

Mar 9 '06 #2

P: n/a
'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
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Srimadhi" wrote:
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!!!!!!!!!

Mar 9 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.