Populate A Listbox Based On A Selected Item In Another Listbox
Ok...I am stumped.
I have a single form that has 3 list boxes. I have 4 public strings containing various values. Based on the selection from lstBox1, I need to populate the ListBox2 and ListBox3 list from values in the public strings. Clear as mud?? That is what I thought!
Example string variable
strLuxury = """Hand Wash"" ""Hand Wax"" ""Check Engine Fluids"" ""Detail Engine Compartment"" ""Detail Under Carriage"" ""Fragrance"" ""Shampoo Carpets"" ""Shampoo Upholstery"" ""Scotchgard"""
ListBox1 contains the following:
Standard Deluxe Executive Luxury
ListBox2 is empty, but is contained in a frame indicating Exterior Options ListBox3 is empty, but is contained in a frame indicating Interior Options
If Luxury is selected in ListBox1, then ListBox2 should contain Hand Wash Hand Wax Check Engine Fluids Detail Engine Compartment Detain Under Carriage
And ListBox3 should contain Fragrance Shampoo Carpets Shampoo Upholstery Scotchgard
If Fragrance is present in ListBox3, a seperate dropdown box should appear allowing selection of the appropriate scent.
Yes, this is a homework assingment.
Thank you in advance for your help! Mark
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Populate ListBox Based On Item Selected In Combobox
Hi!
I really need a help in this. Here is my scenario:
1. I have an ms access database which has 2 different tables: Custom and Clinet.
2. I have a CustomID field in both Custom and Clinet data tables.
3. I have also a form Which has a combox and listbox. The combobox is populated from the Custom data table and the Listbox is populated from the Clinet data tables.
My problem is how can I filter the listbox based on the selected item in combobox. Or I would like the listbox shows only the datas that has the same CustomID as in the CustomID I selected in combobox.
Thanks a lot for any help or some code.
petk65
.: Please Help: Copy Selected Item(s) From A ListBox To The Other ListBox..
Hi everyone!
I'm having problem with copying file to another Listbox, please help..
So, in this case, I have two ListBoxes where the 1st ListBox holds several items..
I need to copy the selected item to the other listbox 'without' a repetition, I mean.. the same item won't copied anymore..
When the user tries to copy the item which have already been in the ListBox2, then a messagebox will pop up to warn the user of the existing item.... So, how should I do that??
Thanks a lot
Populate Listbox Based On Datagrid Selection
Is there an easy way to populate a listbox with the value from selected record in a datagrid? I know how to go the other way around but am stumped on getting this to work.
Thanks in advance!
Populate Datagrid Based On Listbox Values
I have a listbox that has been populated with values from 1 column in my database. There are 100s of records in the database but I just want to show the few that are selected in the listbox in my datagrid. I know how to populate and update the datagrid, but I do not know how to use the listbox values as a string value in my SQL statement. Can someone look at my code and tell me what I'm doing wrong?
Thanks in advance!
Code:
'##Update Datagrid1
Dim MyCon As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim strSQL As String
Dim sValue As String
Dim sScenarioName As String
Dim sListValues As String
'set up the connection to the database
Set MyCon = New ADODB.Connection
MyCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C: est est.mdb;"
Set MyRecSet = New ADODB.Recordset
MyCon.Open
strSQL = "SELECT * FROM test where field1 = '" & lstTest.Text & "'"
With MyRecSet
.CursorLocation = adUseClient
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.ActiveConnection = MyCon
.Open strSQL
End With
Dim objColumns As Columns
Dim strData As String
Dim varBM As Variant
On Error Resume Next
If MyRecSet.RecordCount > 0 Then 'Recordset is not empty
Set DataGrid1.DataSource = MyRecSet
Else 'Recordset is empty
MsgBox "No Records Available"
End If
Listbox Selected Item
Hello again!
I was wondering if anyone knew how to make the selected item from a listbox appear in a text box.
For instance List1 as the list box and Text1 as the text.box? Is it just one of the properties because I have not be able to find it.
Thank you for all your help!
Always Have Last Item In Listbox Selected
How can I make it so the last item in a listbox be selected, even after new items are added. For instance, lets say I had four items in a listbox like this:
I'm one
I'm two
I'm three
I'm four
At this point I'd want "I'm four" to be selected and if I added another item like this:
I'm one
I'm two
I'm three
I'm four
I'm five
Then at this point I would want "I'm five" to be selected. Does anyone know of a way to do this ?
Thanks in advance for any help!
How Do You Get A Selected Listbox Item's Name?
i have a question. how do you get a selected listbox item's name? what i mean is if i selected "yo" from my listbox i want text 1 to be yo when i click a command button or something. plz help. thanks in advance
ListBox Selected Item
Hi.
I need some help on how about doing this:
When a user selects an item in a list box then that item is shown in a text box.
Help, please.
Edited by - Philboy on 9/12/2004 12:30:41 AM
Scroll To Selected Item In Listbox
Hi guys,
I'm in Access. I have a form with a listbox and a combobox with the same values. The user selects the value in combobox, clicks the button, and the same item gets selected in the listbox. The problem is that the listbox doesn't scroll to the selected item automatically. Here is my code:
For i = 0 To Me.storeNumber.ListCount - 1
If Me.storeNumCombo.Value = Me.storeNumber.ItemData(i) Then
Me.storeNumber.Selected(i) = True
End If
Next i
This code selects an item in the listbox every time I press the button leaving previously selected items selected too.
I've been looking for solution suitable for me and found this code:
For i = 0 To Me.storeNumber.ListCount - 1
If Me.storeNumCombo.Value = Me.storeNumber.ItemData(i) Then
Me.storeNumber.setFocus
Me.storeNumber.ListIndex = i
End If
Next i
It does scroll to the selected item. However, every time I click the button it clears previously selected item and selects the new one that I selected in combobox. And I don't need that clearing. Any ideas on how to avoid this? Thanks in advance.
Changing Value Of Item Selected In Listbox
How can I change the value of an item selected in listbox by clicking a command button?
I'm really looking to do something like this:
If an item is selected in ListBox1 and I press Command1 then make the selected item in ListBox1 the value of the selected item in Listbox1 minus 1 character...
If anyone can help I'd be greatly appreciative!
Selected Listbox Item Into A Second Funcion.
I looked everywhere and didn't find an clues to solve my problem. One of wksheets as all my items listed alphabetically. Column A all the a's, B all the b's, etc. I have a userform with a listbox that displays one of my columns based on which letter the user chooses (from my main userform). Each column has a different number of entries, so each respective listbox has a different number of lines in it.
On the same userform (with the listbox) I have a command button that runs a search and display function based on what item is selected in the listbox.
Basically this funcion searches for whatever item name is selected in the list box (the actual text).
I cannot figure out how to get my selected listbox line to display its text in my second function
If C.Value Like "item name" Then.....
So I need the text from the listbox item, to display as item name in my second function
Any help is awesome. Thanks in advance.
Showing A Selected Item In A Listbox
I've got a textbox which the user can input text. I also have a list of already existing items. Doing the search for the item, isn't a problem. However, I wish to select the item, and then make sure it is in the visible portion of the list box.
Actually, getting the item selected isn't a problem. It's getting the selected item into the visible portion of the listbox that is giving me problems. Anyone have any ideas?
Removing A Selected Item From Listbox
I'm not familiar with using the For statement but I gave it a try.
Code:
For i = 1 to 9999
i = lstsFiles.SelCount
lstsFiles.RemoveItem (i)
Next
This didn't work. It gave me an error on lstsFiles.RemoveItem (i). I assume I have it wrong. I removed that line of code, ran it and it froze VB. Now I've gotta restart my program.
How To Make Item In Listbox Selected
i was wondering if anyone could tell me how to make a listbox item (at whichever index) selected...like say my list is
apples
oranges
banannas
pears
how do i make the oranges text in the listbox show up selected?
Removing Listbox Selected Item
How do I remove a user selected item in a listbox. Right now I have....
Code:
Private Sub Command3_Click()
lbo(RemoveItem) = lbo(SelectedItem)
End Sub
Where "lbo" is the name of the listbox. But that just yields a command button that does nothing at all.
I have anoter selected item that works similar (which works), where it gets the selected item in the listbox and sends it to the web browser
Code:
Private Sub Command1_Click()
Denlou.WebBrowser1.Navigate lbo(SelectedItem)
Unload favorites
End Sub
And I can't remove the equals sign because it returns "Expected: End of Statement"
Anyone know what to do?
Deleting A Selected Item From A Listbox
Hi there,
I`ve just joined this forum. I was wondering if anyone could help me?
I`ve made a listbox, populated with data from a table in access, with the column heading test.
I want to be able to select an item from the listbox, click on a button and then delete the item from the listbox and database. I have managed to do this, however the item deleted from the database is the first item and not the selected.
Any ideas?
Heres my code....
Private Sub CommandButtonDelete_Click()
Dim vConnection As New ADODB.Connection
Dim vRecordSetTest As New ADODB.Recordset
Dim vConnectionState As Integer
Set vRecordSetTest = New ADODB.Recordset
vConnection.ConnectionString = "data source=G:FilingLabel.mdb;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open
vRecordSetTest.Open "TableTest", vConnection, adOpenKeyset, adLockOptimistic
vRecordSetTest.Delete
ListBox1.RemoveItem ListBox1.ListIndex
End Sub
Delete Selected Item In Listbox?
Now I need a little help with deleting a item in the list box.
so the name that is highlighted I wanna remove from the item list but only that item not the whole list.
Thanks !
Telling Which Item Is Selected In A Listbox.
How can I tell what item is selected in a listbox?
edit- believe I figured it out, list1.selected(0)? And how can I put that in a select case? I don't know what I'd put instead of 0 for select case list1.selected(?)
Easy - Tell If Last Item In Listbox Is Selected.
What is a quick and simple way I can tell if the last item in a listbox is selected ? There is no multi-select enabled in the list either. I am doing it using listcount, and index but I get the feeling I am making it way more complicated then it needs to be. If you have an answer could you throw it in an if statement so that it will put up a msg box saying either "Last item selected", or "Last item not selected". ~Many Thank, Bryan J. Casler
Checking To See If Item In A ListBox Is Selected
VB Code:
Private Sub lstBuddies_Click() Dim bSelected As Boolean bSelected = False For x = 0 To lstBuddies.ListCount If lstBuddies.Selected(x) Then bSelected = True End If Next x If bSelected = True Then cmdRemoveBuddy.Enabled = True Else cmdRemoveBuddy.Enabled = False End IfEnd Sub
This won't work, but if I put a number in place of x, it will work. Whats that all about?
Color Of Selected Item In Listbox...
Hello
quick question... is there an API or something to change the color of the highlighting when a record in a listbox is selected? by default it's an ugly blue, and that really doesn't suit my program's tastes ... maybe there is no way, but it would be nice.... thanks for the help!
Listbox Selected Item - Wierd Or Just Me ?
Hi guys,
This has been doing my head in all afternoon. I have a listbox on my form which reads it's data from an Access DB. I also have a normal textbox on my form.
If you select an item in the listbox it becomes highlighted, no problems so far. But, if you then click on the textbox the item un-selects itself. I cannot understand why. I have tried as a test, putting another listbox on the form and filled it's contents at design-time with numbers 1,2,3 etc,,. When this is run you can select an item in the test listbox, click on the textbox and it is still selected.
Any ideas why the first listbox keeps unselecting itself? Is it because the data in it is read from a DB ?
Cheers
How To Delete Selected Item At The Listbox.
Hi everyone,
I have two list boxes. one of them is for item another one is for price.
example
Hamburger $3.00
Chicken Nugget $2.00
Muncher $1.50
for example the above items are added to the listbox after clicking the picture. if i dont want the chicken nugget, how can i sure when i select it, the value in the two list box are deleted/remove from the list box.
Thank you. all of you in here are great help to me.
from
swatchgal
How To Scroll A Listbox To Display Selected Item
My problem is as follows:
I have a listbox and my program selects a certain item based on coded algorithms. The listbox contains many more items than can be displayed at one time, so I have to use the scroll bar to search through the content of the listbox.
When my program selects an item in a listbox that is not currently in the view frame, I have to find the item by manually scrolling up or down until I can see it.
I would like my listbox to scroll automatically so that the selected item is in view.
I have not found a way to find out which items are displayed, or even to programmatically make the list scroll.
Any suggestion?
Thanks in advance
Listbox: Change Text Of Selected Item
hi all,
just wondering if anyone knows a way of changing the text of the selcected item in a list box?
for example: if i have a listbox with the following list items:
one
two
three
four
and "two" is selected, and i need to change its text to "this one".
i would like to avoid regenerating the list by clearing it and adding all the items again if possible.
thanks for your time and consideration,
mojoinst
Retrieve Info From Selected Item In A Listbox
I have managed to display a listbox with similar addresses on for the user to choose from. Those addresses are strings, which combined from a few variables, eg. streetnumber, streetname and postcode.
My next step is to return the chosen ltem back to VB to continue. My problem is how the value for each field (streetnumber, etc) on the selected item could be saved and passed back to VB?? ........
Any help is much appreciated.
Popup Msgbox For No Selected Item In Listbox
How do I got the pop up when no item is selected in the listbox?
Code:
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
SelectLayerByName (ListBox1.List(i))
End If
Next
Send Selected Listbox Item To Textbox
The title says it all. I want to send the selected listbox item text to a textbox. I need to use this in a timer so the selected item will go down the list and it will send it to the textbox every X amount of seconds. Thanks for all your help!
If Checkbox Checked And Item Not Selected From ListBox BUT...
I have a checkbox and a combobox working together where if the checkbox (commute) is checked but nothing is selected from the list (car, bus, carpool, ferry, etc.) I have a code like this:
If chkCommute.Value And cboCommute.ListIndex = -1 Then 'checked but nothing selected in listbox
MsgBox "You must select a mode of transportation or enter another mode", , "Missing Info"'select a mode since you checked the box
cboCommute.SetFocus
Exit Sub
End if
And it works fine but I want it to go the opposite way - if a mode of transportation is selected but the checkbox not checked THEN...whatever. This info goes to an array that gets printed out. If I select a mode of transportation but don't check the checkbox and press enter the mode of transportation won't show up on the list. What would be a good way to make it come out? Anyone up for this? Thanks.
Frames That Would Follow The Selected Item In A ListBox
Hi there,
I have a ListBox with > 100 items, at the same time I have a Frame which has multible CheckBoxes. The Q is:
How can I make the frame move up/down with whichever is selected from the listbox ??
I have this code:
Code:
Private Sub Form_Load()
Frame1.Left = List1.Left + List1.Width
Frame1.Top = List1.Top - 180
End sub
Private Sub List1_Click()
Frame1.Top = List1.ListIndex * 300
End Sub
The 2 problems i'm having are:
- The Listindex When it's (0) ??
- When selecting item > 20 , the Frame would be Hidden !?
Thanx for any help.
Scroll Selected Item To Top In ListBox Control
I have a multiple select list box control on an aspx page controlled by VB code. I only have enough real estate to show 5 items in the list at any one time, therefore, the list box contains more items than will show at any one time. When an items is selected, the OnSelectedIndexChanged event is fired which gathers the selected items for later processing and the aspx is refreshed. This all works fine with the following problem, the refresh of the aspx always shows the very top portion of the list in the list box control regardless of which items are selected. How do I force it to automatically scroll down to the first selected item in the list if this item is not in the topmost portion of the list? In PowerBuilder, I would just do a ScrollToTop and supply it with the index of the item I wanted it to scroll to. I cannot find any way to do that with VB. Any help would be greatly appreciated. Thanks in advance for your help.
Loading A Form When Item In Listbox Is Selected
Hi guys and gals.
I want to be able to select a specific name in a listbox that will load a form with a flexgrid on it, which will have data from a table loaded into it. Now I can do all this if I have just 1 name in the list. I want to be able to click on any name and load a form with that names personal table. Thanks in advance.
Daz
How To Use Value Of Selected Item In Access 2000 Form Listbox
I have a listbox on a form in Access 2000. Using VBA, I run a search of files within a certain directory, and then display the results in the listbox. The items are added using the "Row Source" value in the listbox.
What I would like to do is enable the user to double-click one of the files in the list, and have the file open. I was trying to use the following code, but am unsure how to reference the selected file value:
-----
Dim strSelected As String
strSelected = ListBox1.???
Application.FollowHyperlink (strSelected)
-----
Any help would be appreciated!
Thanks in advance,
Malcolm
Simple Listbox Question - Removing Selected Item
Easy question for you all - how can I have the user click a button and have a select listbox item removed? I cannot seem to get this, as i always needs its index.
To rephase, I need to be able to tell what the index is of the selected item in a listbox, when the contents are changing (the user inputs the contents).
Any ideas would be great! Thanks!
Item Selected In Listbox Determines Variable To Fill
I know I'm missing something simple because I've written 1st grade code my procedure is too large to compile. I have an array of 7 list boxes. Each list box contains 80 numbers which correspond to a competitor. When the competitor is selected in the list box I need to add the value in the corresponding text box to their accumulated score. (See below a small sample)
Since I have done this 80 times for each listbox the code is too large to compile. What am I missing to shorten it?
Sub GetUserProsecution()
If lstMemberIDProsecution(0).Text = 1 Then intID1 = txtPCA.Text + intID1 Else
If lstMemberIDProsecution(0).Text = 2 Then intID2 = txtPCA.Text + intID2 Else
If lstMemberIDProsecution(0).Text = 3 Then intID3 = txtPCA.Text + intID3 Else
If lstMemberIDProsecution(0).Text = 4 Then intID4 = txtPCA.Text + intID4 Else
If lstMemberIDProsecution(0).Text = 5 Then intID5 = txtPCA.Text + intID5 Else
If lstMemberIDProsecution(0).Text = 6 Then intID6 = txtPCA.Text + intID6 Else
If lstMemberIDProsecution(0).Text = 7 Then intID7 = txtPCA.Text + intID7 Else
Resolved: Remebering Previously Selected Item In Listbox
Hi
I hope you can help me. I'm creating a games organiser in VB6, been at it for a while now and I'm stuck
I have a listbox and a database which VB connects to using ADO. The database holds a list of games each with a unique number to identify it. The games are listed in the listbox in VB and the id for each game is in the item data. This is the code I'm using to fill the listbox with games:
VB Code:
Private Sub Form_Load() Dim rs as ADODB.Recordset Set rs = new ADODB.Recordset rs.Open "Select GameID, GameTitle From Games", cn Do Until Recordset.EOF List1.AddItem rs.Fields("GameTitle").Value List1.ItemData(List1.NewIndex) = rs.Fields("GameId").Value rs.MoveNext Loop rs.Close Set rs = NothingEnd Sub
Now what I want to do is when I select a game, I want it to be remembered so when I reload the program it displays the game I last selected.
I know I can use SaveSetting and GetSetting to do this but I can't seem to figure out how to get the games id from the index in the item data when I reload the program it selects the wrong game
I can't use the ListIndex value because the List can have different views (Playable, All, Non-Playable) with different games in each list
Any ideas how I could solve this problem?
Many thanks,
Robert
Listbox First Item Selected On Load *Weird But Resolved*
Is it possible to have the first item selected on Form Load.
I've been playing around with listindex to make it 0 instead of -1 but not working out - Getting errors. The question seems easy but i may be mistaken.
i tried
listbox.listindex=0
|