473,396 Members | 1,756 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,396 software developers and data experts.

Select an item from combo box then display to list box?

I have a combobox and a listbox. When the user select an item from the combobox, then the listbox will show a certain data. How do I do this?

Thank you in advance.
Oct 15 '09 #1
6 18623
debasisdas
8,127 Expert 4TB
Is both the the controls being populated from database ?
Oct 16 '09 #2
@debasisdas
No. It's like this:

I have a combobox that shows two options: for example, maybe day and night. If the user selects day, a certain item is going to be displayed in the list box, but they are not from database. It's gonna be in the coding. It sounds simple...hopefully you can understand what I'm trying to explain. Not good at explaining, really.
Oct 16 '09 #3
Guido Geurs
767 Expert 512MB
dear,

like this:?

form with combobox1 and listbox1

===========================
Option Explicit


Private Sub Form_Load()
Dim i As Integer
For i = 1 To 9
Combo1.AddItem "item " & i
Next
End Sub

Private Sub Combo1_Click()
List1.AddItem (Combo1.Text)
End Sub



=============================
Oct 16 '09 #4
@ggeu
No, but close.

Actually the items of the combobox was determined in the design of the form, so when user clicked on an item from the combobox, then something will appear on the listbox. This is what I have in mind:

==================================
'courts is one of the item of the combobox.
If combobox.selecteditem = "courts" Then
lstbox = "I'm going to add something here."

==================================

obviously my code is wrong. But is it possible to do this kind of thing?
Oct 16 '09 #5
Guido Geurs
767 Expert 512MB
dear,

You have to make the link from the value in the combobox to the value in the listbox.
You can do this with a array in the background.
Like: each string in this array has 2 data separeted with a char that not can be present in the used data like= # or | or ...
I have used # in the example.
You can load the data from inside the form or better: from a file with the data strings (data is better to modify afterwards).

When You select a value in the combo, it looks in the array for the LEFT part of the string and puts the RIGHT part in the listbox.

Create a form with combobox1 and listbox1

code=
======================================
Option Explicit
'§ declare a 1 dimensional array
Dim table() As String

Private Sub Form_Load()
Dim i As Integer
'§ fill the array with string= "number 1#value = 1", "number 2#value = 2", ...
For i = 1 To 9
ReDim Preserve table(i) As String
table(i) = "number " & i & "#" & "value = " & i
'§ fill the combobox with the LEFT string to char "#"= "number 1", "number 2", ...
Combo1.AddItem Left(table(i), InStr(table(i), "#") - 1)
Next
End Sub

Private Sub Combo1_Click()
Dim i As Integer
'§ seek in the table for the LEFT string in the combo selection and
'§ put the string right of the "#" in the listbox ="value = 1" OR "value = 2" OR ...
For i = 1 To UBound(table)
If Left(table(i), InStr(table(i), "#") - 1) = Combo1.Text Then _
List1.AddItem Mid(table(i), InStr(table(i), "#") + 1)
Next
End Sub


======================================
Oct 17 '09 #6
@ggeu
Thanks for this! I think I will try and do this later, hopefully it will work. (I have so many assignments to finish!)

Thank you for your help, everyone =)
Oct 18 '09 #7

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

Similar topics

3
by: keithsimpson3973 | last post by:
I have 6 combo boxes on a vb form. Is there a way, using vb6, to remove the list item that was selected in the first combo box from the list of the second, third fourth, fifth, and sixth combo box...
2
by: JweldonH | last post by:
My issue probably has a simple answer. I want to limit a populated combo box to items that are NOT in use in another table. I have a Table with a field that looks up values from another table via...
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
13
by: helm | last post by:
Folks, There's some great help, in this forum on the combo box Not in List event and it works fine for me. I can recognise the event, accept the newdata, add some additional record info via a form...
13
by: Mel | last post by:
i would like set my <Selectoptions from a list AFTER the form is created and a list of urls for those selections from javascript. How can i do this My select may have a list like: "Go to One",...
5
neo008
by: neo008 | last post by:
Hi All, How can I select a combo box item programatically. I am using VB6 and I have populated a combo box from database. NE☼
3
by: Lohboy | last post by:
Using ASP.NET and IE7. (Sorry if I am posting in the wrong forum but my problem seemed to be more related to the JavaScript side than the ASP.NET side.) I have two DropDownList controls the...
4
by: lulu123 | last post by:
here's my problem 1) rowsource .RowSource = "select distinct , " & "from Projects " & " where =" & Me! I have the above code, and it works fine. however, i want to make the combo box in...
2
vikas251074
by: vikas251074 | last post by:
I am creating an application for official use. This application will be used by employees to take items for official use. I have a list, presently this list contains three items - 1) Cartridges, ...
4
by: mistyblu | last post by:
I wrote an Access97 application using VBA for a company many moons ago and they have approximately 20 users. All has been hunky dory for a long time but suddenly they have a combo box error on 3 of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.