Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List Box problems

Status
Not open for further replies.

nomi2000

ISP
Feb 15, 2001
676
0
0
CA
Hi guys
I have two list boxes and i want to move some items from one list to other list box so i have 4 buttons for
1) add selected items from listbox1 to listbox2
2) add all items from listbox1 to listbox2
3) remove selcted items from listbox2
4) remove all from listbox2
can some one help me how i can achieve this?
also i want to hide something behind the listbox in Visual basic 6.0 i can do this by "ItemData" but is anything similar to this in .Net listbox? i want to hide ID behind the data
thanks in advance
nouman
 
Yeah, you can do both.

If you were say, transfering a selected item to list box 2, in your button, you might have something like:

ListBox2.Items.Add(ListBox1.SelectedItem)

As far as the VALUE of an item, its not like the list control in Web Forms. Look at this article in help "ListControl.ValueMember Property" about using ArrayLists.

 
thanks river guy
but still i didn't get the complete answer will you let me give the URL which you are telling
thanks again
Nouman
 
I was meaning the article within the .Net IDE. Under help, type that in.
 
dear river guy
thanks
yup i find that thing for binding but problem is that i dunno wanna do binding becuase if i bind the listbox then
i can't remove items from it
thanks
Nouman
 
any body can help me around ,i m in urgent need of it
thanks
Nouman
 
Better late than never!

'### To add
Dim intX As Integer
Dim strCode As String
Dim strName As String

For intX = 0 To lstListbox.Items.Count - 1
If lstPractices.Items(intX).Selected Then
'### Copy into Selected box
strCode = lstListbox.Items(intX).Value
strName = lstListbox.Items(intX).Text
lstSelectedListbox.Items.Add(New ListItem(strName, strCode))
End If
Next


'### To Remove - add in a loop to remove all
Dim lsiItem As ListItem = New ListItem()
lsiItem = lstSelectedListbox.SelectedItem
lstSelectedListbox.Items.Remove(lsiItem)

May not be the best way, but I'm new to .NET and it works for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top