473,322 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Listboxes

I am trying to select multiple items in a listbox and place the values into a textbox on another form in vb6. I just can't seem to get it right. If I select 3 items, it only returns the last item selected? Please help!
Apr 16 '07 #1
7 1681
It should look something like this as far as I can tell. This is not my code, I found this information here:

http://www.thescripts.com/forum/thread399839.html

Expand|Select|Wrap|Line Numbers
  1. Dim objX as Object
  2. For Each objX in lstBox.SelectedItems
  3.     'Do Something
  4. Next
  5.  
Apr 16 '07 #2
Thanks. But selectedItems is not a valid method or property for my listbox?
Apr 16 '07 #3
devonknows
137 100+
It should look something like this as far as I can tell. This is not my code, I found this information here:

http://www.thescripts.com/forum/thread399839.html

Expand|Select|Wrap|Line Numbers
  1. Dim objX as Object
  2. For Each objX in lstBox.SelectedItems
  3.     'Do Something
  4. Next
  5.  
If you are using VB 6 or below the problem is there isnt a .SelectedItems Method, that is .NET and the link is for .NET, something like this could be of help to you

Going on the basis that your other form is called "MyFormName" which you can change lol, The text box you are transfering the information to is called "Text1" and the List

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim i As Integer
  3.  
  4.     MyFormName.Text1.Text = "" 'Clear The Text Box For Use
  5.     MyFormName.Text1.MultiLine = True 'Make Sure The Text Box Is Multiline
  6.  
  7.     'Loop through the items in the List Box (Named: List1)
  8.     For i = 0 To List1.ListCount - 1
  9.  
  10.         If List1.Selected(i) = True Then     'If The List Item Is Selected
  11.  
  12.             With MyFormName 'With The Other Form
  13.  
  14.                 .Text1.Text = .Text1.Text & List1.List(i) 'Add The Selected Text
  15.                 .Text1.Text = .Text1.Text & vbCrLf        'Next Line After The Added Text
  16.  
  17.             End With            'End With The Other Form
  18.         End If
  19.     Next
  20.     MyFormName.Show          'Show the other form.
  21. End Sub
Comments are included so that you can determine what each line of code does, (Turns green when in the code explorer screen), but i hope this helps you

Brief Rundown:
For i = 0 to List1.listcount - 1 : The listbox's list starts at 0, where as the count does not, so to stop it getting confused - 1 from the list count
vbCrLf: Next line
With MyFormName: means you dont have to type out MyFormName.Text1.Text everytime you want to do something with an object on that particular form.

Hope This Helps
Kind Regards
Devon.
Apr 16 '07 #4
Thanks Devon. It works beautifully!
Apr 16 '07 #5
Sorry, I missed the vb6 part. Thank you for the correction, devon.
Apr 16 '07 #6
devonknows
137 100+
Its quite alright, glad to help i know when i struggle for things i want people to help me so i return the favour when i can, The comments should give you all the guidance you need with it, pretty self explanatory...

Sorry, I missed the vb6 part. Thank you for the correction, devon.
Sorry for the abruptness, was a bit hungover this afternoon :P but i looked and thought... Im sure it doesnt have SelectedItems, unless ive been going about it the wrong way all this time rofl.

Kind Regards
Devon
Apr 16 '07 #7
Yesterday morning I had my right half of my body kinda jerk, and felt really bad all of a sudden. I was somewhat disoriented but tried to go about my daily routine. I eventually went to the hospital, but I missed many simple things yesterday due to being disorented, so I appologize for making mistakes yesterday by answering questions when I should have been going to a doctor.
Apr 17 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jeffrey Barish | last post by:
I have an application that produces two listboxes. I would like to be able to select one of the items in the first listbox and one of the items in the second listbox. However, when I make my...
3
by: softengine | last post by:
Can and how do you alter a data view to include a look up field from another data table? The data table of the dataview only has the key, the value I need is in another data table. Can and how...
3
by: Simon Templar | last post by:
I need the following functionality: With 2 listboxes populated from a database with the SAME data, I need any of the listboxes to stop displaying the option when selected at the other listbox. Eg:...
9
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
4
by: bill yeager | last post by:
I have several template columns inside of a datagrid. Inside of these template columns are databound listboxes: <asp:TemplateColumn HeaderText="Crew Chiefs"> <ItemTemplate> <asp:listbox...
0
by: Terry D | last post by:
I'm having an issue with an ASP.NET page (VS.NET 2003, VB.NET, Oracle back end). The page uses the standard VS.NET grid to display the records from a particular table. The user can edit certain...
1
by: Ryan Ternier | last post by:
I have two listboxes, and allow users to move items between them via the following function: function SwitchList(fbox, tbox){ var arrFbox = new Array(); var arrTbox = new Array(); var...
0
by: Luis Esteban Valencia | last post by:
have a problem and I'm not sure how to handle/fix it. I have three listboxes on my page. The first listbox has a list of software products. When you select an item in the Products listbox, then...
2
by: salad | last post by:
This is a tip on how to speed up listboxes DRAMATICALLY. Persons that would benefit are those that are constantly updating the rowsource of a listbox/combobox in order to filter and sort the data...
0
by: amidala | last post by:
Hello, everyone, i've recently started using C# and i'm rather new to this language. I'm trying to make a small project now that is combining the basic knowledge of programming (according to me :) )....
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.