Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Check If Listbox Is Selected? [RESOLVED!]

I need to check whether or not an item in my list box is selected. So basically if it is then MsgBox ("Action 1") and if it isnt ("Actions 2")

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Check Selected Value Of Listbox
Hi there. Can anyone tell me how to retrieve the selected value of listbox and do some validation?

For instance, if I got the following listbox

2004/019 'this one was selected/clicked by user

and in worksheet1, there were data as follows:

1 2004/001
2 2004/013
3 2004/015
4 2004/019 selected
5 2004/023

if selected value of listbox = range("a" & whichever).value then
range("c" & whichever).value = "Selected"

I could not figure out the correct vba codes for the above.
Please help.


Check If File Listbox Has Item Selected?
How can i check that an item has been selected from the File List Box? This is so it stops you from closing the form unless a file is selected.


No Items Selected In A Listbox? *RESOLVED*
I have 2 listboxes side-by-side. When I click on one, I want the "selection" in the other to disappear. I've looked that the controls and played around with it a bit, and I can't figure it out...

***INSTANTLY RESOLVED****Selected Item In A ListBox
Please have a look at the attached picture & assist me in how can I save the selected name in that ListBox into a Variable...

Resolved: Remebering Previously Selected Item In Listbox

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,

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

RESOLVED - Return A String Of Selected Items In Listbox
I have a listbox that is populated with years.

2001 <-Selected
2002 <-Selected
2004 <-Selected

I want to return a string based upon the selections made.

Example: 2001,2002,2004

Dim z As Integer
Dim Ystr as String

For z = 0 To (lstForecastYears.ListCount - 1)
If lstForecastYears.Selected(z) = True Then
Ystr = lstForecastYears.List(z)
End If
Msgbox Ystr

I'm returning the correct selections but how do I get into a string format with the delimiters?


[Resoved] Listview.Selected=Listbox.Selected
I have Listview1 and Listbox1, both with the same exact items and both set to MultiSelect=True. When the user selects mulitple items in the Listview I want the same items to be selected in the Listbox. Can anyone help with this?

Drag Listbox Entry To Another Listbox; Selected Text Drags With Mouse Cursor
Hello everybody; new member! I am trying to figure out (in VB6) how to drag a listbox item and drop it into another listbox. That's the easy part and already have basic drag and drop mechanics down pat. What's stumping me is this... I wish to have the text contained in the original listbox entry follow the mouse cursor as I am dragging to the destination textbox. This would, in effect, be a custom drag icon. I have experimented with some API direct printing but not much success (especially when mouse cursor goes over container controls; text just slides under them!). I appreciate any help anyone can give in this area. Thanks! GumbyTheCat

Please What Kind Of Control That Displays Multiple Records And Has A Check Boxes So That I Can Check The Selected Records And Save Them In VB6.0?
Please what kind of control that displays multiple records and has a check boxes so that I can check the selected records and save them in VB6.0? ...?

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:


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
Shampoo Carpets
Shampoo Upholstery

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!

.: 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

Check If Row Is Selected??
I'm trying to get my macro to act on the selected rows only, as compared to running through all rows from top to bottom. Is there a way to check the status of the row as the activecell moves down the spreadsheet? If not selected then go to next row and check again. THANKS.

For example:

Sub Loop_Selected_Rows()


For x = 1 To NumRows

ActiveCell.Offset(1, 0).Activate
' I assumed using .select would unselect the selecte rows. Not sure if activate would work

'If row is selected Then
' do stuff here
'End If

Next x

End Sub

Check Which Form Is Currently Selected

Dumb newbie question (Probably)

How do I check which form the user has selcected? I thought it may be
something like:

Dim IsSelected as Boolean

IsSelected = frmTest.selected

[Thats pseudocode]

What do i use, because forms dont have a ".selected" property.



Check If Nothing Is Selected In Listview
I am using this code to check if any record has been selected in a listview, which works, except that now, the first column is just icons, and it always returns lvwItem = Nothing, even if a record is selected.
Is this because the text is in the second column?

Set lvwItem = lvwToDo.HitTest(x, y)

If Not lvwItem Is Nothing Then
lngToDoSelection = lvwToDo.SelectedItem.SubItems(2)
End If

Check If Window Is Selected
I know how to check if a window is open, but is there a way that I can check if it's active? For example let's say I have a program open, and calculator, and I know that they're both open, but I want to check if calculator is being used with the program running in the background (visible) and if it is, to msgbox "calculator is being used", but if the program is being used with calculator behind it/minimized, then msgbox "calculator is open, but not being used". How can I do this?

ComboBox What To Use To Check Selected Value
I have a comboBox with the values 1 - 10. If the user selects 5 I want to prompt message.

if combobox.value = 5 then
msgbox "You have selected 5"
end if

I am sure this is easy I just can't figure it out. I have tried onChange, Validate, but these seem to also occur when you move from one record to the next and the value in the combo box changes. If I place code in the on click, it executes prior to the user actually selecting a value on the drop down. I only want it to execute when they have finished selecting the value. The best thing I have found so far is to do it on lost focus but that requires them to leave the field and go to another.

I hope I have made sense.

Thanks in advance

How To Check If Selected Records
i have a question

how to check if user selected any records in datagrid?

DataGrid1..... ?

Check If Text Selected...
ok, basically I want to check if any text has been selected in a textbox, like...when i click a command button, i wanna check to see if the user has any text selected...and if there is text selected, i want to do something to specifically that text, instead of the entire textbox...but i need to check if there is actually text selected or not, so I can create msgboxes saying "you need to select text first" sort of thing...
...i've been searching/experimenting all night, and cant figure out how to do this...i dont know if its possible or not, so if anyone can tell me if/how its possible, i'd greatly appreiciate it.
yes...i know i've been rambling most of this...but i didnt have me coffee
anyhoo, help is appreiciated...

Check If ListView Item Is Selected

Is it possible to check if a ListView item is selected without using a loop?

Sebastian Mares

ListView: How To Check If There Is An Item Selected?
Any ideas? I have tried using a thousand different codes and i can't get it to work :/
I have tried using the property Listview1.SelectedItem.Selected and i get a runtime error :S

Any ideas?

Get Selected Values Of Option Box And Check Box
how do i get the selected values of option box and check box.

How To Check Dtpicker Checkbox Is Selected Or Not
i want to check whether dtpicker checkbox is selected or not
i have one table with date column
and date column value may be null or may be with date
and i want to show that in dtpicker with check box selection or not selected.
for example if date column value is null then i want to show checkbox is unchecked.
and if date column value is some date then i want to show checkbox is checked

Check To See If An Item In The List1 Is Selected.
Hello there everyone!

The code below gets the selceted List1 item and deletes the file that the name is associated with..

See I have other code that gets all the files out of the folder C:progPlugins and display there filenames in list1

And then the code below will delete the file from the list and from C:ProgPlugins.

What I want this code to do is all that it does except if there isn't any file selected in List1 then I want to display a msgbox saying "No file selected"

So my question is:

How do I get it to tell if there is a selected item in List1 and if not display the msgbox?

VB Code:
Private Sub Command1_Click() Dim iResponse As Integer    iResponse% = MsgBox("Are you sure you want to delete the selected message file?", vbQuestion + vbYesNo, "Delete?")If iResponse% = vbYes Then Dim i As LongFor i = 0 To List1.ListCount - 1    If List1.Selected(i) Then       Close       Kill "C:ProgPlugins" & List1.List(i)  'That is the path       List1.RemoveItem List1.ListIndex        Exit Sub    End IfNext Else End If End Sub

Thank you all!

Check If Item In Listview Is Selected
I have searched these forums, but have not found a answer that works.

Here is my problem:
When i item in the listview is not selected, then it needs to exit sub

Listview - How To Check Whether Any Item Selected
I am using the listview control. I would like to know that how do I check whether a user has selected any item in the list or not ?

Check For Selected Text In A Webbrowser Control?
How can I check if the webpage loaded in the webbrowser has any etxt selected in it, and if YES then retrive the text??

please let me know.

basically I am trying to do this

if Screen.ActiveControl.SelLength <> 0 then
'Enable the copy function
'Get the selected text
'disable the copy function!
end if

This code works for a normal textbox but not a webbrowser, anyone know what I can do??

How Check If An Excel Cell Is Selected(activated)
Hey guys...i need help. I have a question for you. I am working with an Excel worksheet. The answer is which is the function (or something) to see if a cell is selected (activated). I think there should be some boolean (when is selected to be true and in the other way to be false). So...I need your help..plsss. I wait your answer

*RESOLVED* Getting Selected Item In List View To Move Into View*RESOLVED*
Hi, I am trying to get a List View to act like a combo box. At the top of the List View there is a text box where the following code searches the List View for the text entered, I have this code in the Change event of the text box so a search is done on each letter typed.

The code finds the record without a problem but I want it to move to the top or into view. Right now I have to scroll down to find the record it selected. Anyone have any ideas? Here is my code:

Private Sub txtFindFirst_Change()
Dim i As Integer
Dim l As Long
On Error GoTo NoRecord

If txtFindFirst = "" Then
GoTo NoRecord
l = Len(txtFindFirst.Text)
For i = 1 To lstContacts.ListItems.Count Step 1
If StrConv(txtFindFirst, vbUpperCase) = StrConv(Left(lstContacts.ListItems(i).Text, l), vbUpperCase) Then
lstContacts.ListItems(i).Selected = True
Exit Sub
End If
End If

On Error GoTo NoList
lstContacts.ListItems(1).Selected = True
strTransferID = lstContacts.SelectedItem.ListSubItems(1).Text
Exit Sub

Exit Sub
End Sub

Thanks in advance for any help.

How Do I Check If The User Selected A Valid Entry For A Datacombo Box?
For a normal combo box, I just do a check if the ListIndex = -1, but what about DataCombo box? The DCB does not have a list index property, so what should I use? I can't check for BoundText = "" either, because the user can type gibberish into the DCB and the check won't pick it up.



Edited by - Chewbacca789 on 4/23/2004 2:28:10 AM

Listbox.selected....not Again
How would i check if items in a listbox were already selected when looping through the same listbox in order not too perform procedures again for those already selected.


Listbox Selected
Ok I have items in my listbox and a command button and when I press the command button I want it to take what ever item is selected in list 1 and open a website? SO how can I do this? Thanks in advance

Getting Selected ListBox Value
Have listbox filled with values.

Program runs okay, BUT ... listbox value is only updated iff user SELECTS and then CLICKS on the value again after selection.

I am sure that I am doing something wrong, or missing something.

As long as I SELECT a value, and THEN CLICK on the listbox value after selection, the value selected is used, otherwise uses the initial/original value.


Selected Row In A Listbox
How do you know the selected row (item) in a listbox just like in a MSH Flex grid? I need this property to remove this item from the listbox.

the code i have know is like this:

listfault.ListIndex = ???? 'here i need the set the index on the selected item

can you help me?

Code To Check If 5 Select Buttons In An Array All Haven't Been Selected?

I've got 5 select buttons in an array, and I want to do something if they're all not selected, button names are typeselect(0) - (4)
So IF (none are selected)

Any help appreciated greatly!

Listbox Selected Color
I have a list box that works with a timer. As the items in the list are processed the selected property is set to true. It all works fine but I hate the color. Is there a way (in code) to change the color without changing the entire windows color scheme?


ListBox Selected Problem
I can't figure out how to get this to work again, I messed with it and am having problems now. What I have is an Equip Form with a ListBox and Option Buttons for armor, weapons, ect. an a command button to equip them. The weapons or armor will show in the listbox of what you have boughten and want to equip. Now heres my problem. When I go to equip it they may not be in the same order everytime, and to tell what you have selected and want to I ran into this problem. This code is the equiping part. The equipweapon and all that is only to see if u have another item fo that catogory equiped ect the problem is where i marked it; the listbox selected. The item may not be in the order I have and thats where the error comes.

If OptWeapons.Value = True Then

If Weapon = False Then
If ShortDagger >= 1 Then
If ListEquip.Selected(0) Then <============right here
WeaponName = ListEquip.List(ListEquip.ListIndex)
EquipShortDagger = True
If EquipShortDagger = True Then
WeaponStrength = 5
Strength = Strength + WeaponStrength
ShortDagger = ShortDagger - 1
Weapon = True
WeaponEquiped = "ShortDagger"
LblWeapon.Caption = WeaponEquiped
End If
End If
End If
End If

If Weapon = False Then
If LongSword >= 1 Then
If ListEquip.Selected(1) Then <====here
WeaponName = ListEquip.List(ListEquip.ListIndex)
EquipLongSword = True
If EquipLongSword = True Then
WeaponStrength = 20
Strength = Strength + WeaponStrength
LongSword = LongSword - 1
Weapon = True
WeaponEquiped = "LongSword"
LblWeapon.Caption = WeaponEquiped
End If
End If
End If
End If

If Weapon = False Then
If WoodenSword >= 1 Then
If ListEquip.Selected(2) Then <==== here
WeaponName = ListEquip.List(ListEquip.ListIndex)
EquipWoodenSword = True
If EquipWoodenSword = True Then
WeaponStrength = 10
Strength = Strength + WeaponStrength
WoodenSword = WoodenSword - 1
Weapon = True
WeaponEquiped = "WoodenSword"
LblWeapon.Caption = WeaponEquiped
End If
End If
End If
End If

End If

Could someone help me with this, and thanks to everyone else I didn't think in the past for helping.

Saving Selected Listbox.
Alright, I know how to save everything in a listbox to a file. My question is how can a save the selected things in a listbox to a file. Thanks!

Selected Elements At The Top Of A Listbox?
Hello, I want to do multiselection on a list box with many items. My pourpose is to see at the top of the list box the selected elements when finish the selection. I'm using a curious custom listbox that automaticaly expands at get focus.
Can you help me please?
Thank you very much

here's the code I use
(put a listbox and a timer "tmrWait")
Option Explicit

Private Sub Form_Load()
tmrWait.Interval = 50
tmrWait.Enabled = False

List1.AddItem "cat"
List1.AddItem "dog"
List1.AddItem "horse"
List1.AddItem "elephant"
List1.AddItem "lion"
List1.AddItem "panda"
List1.Height = 120
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

With List1
If X < .Left Or X > .Left + .Width Or Y < .Top Or Y > .Top + .Height Then
.Height = 120
tmrWait.Enabled = False
End If
End With
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
tmrWait.Enabled = True
End Sub

Private Sub tmrWait_Timer()
List1.Height = 2000
End Sub

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 Is it just one of the properties because I have not be able to find it.

Thank you for all your help!

Listbox Selected Style
Is there any way that I could shade the checkbox on a listbox because I can see is to options either Selected = True or Selected =False

Any help would be greatly Appreciated

Listbox Selected Question
I have an array of listboxes.. (10 in total)

Whats the best method to unselect any selection in the other 9 listboxes when an item in any ONE listbox is selected?

Basically, I only want 1 item of 1 listbox to be selected at any given time.

Using Listbox Selected Items
ok so I have a listbox with several items and I want to do a msgbox on what item is selected in the listbox. How can I do so?

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!

Selected Item In A Listbox
how do i find the selected item in a listbox???

Listbox.selected Question
When I add an item to listbox2 from listbox1, the item in listbox2 is not automatically selected. In fact no items are selected in it, which I think is weird . Listbox2 is starting out empty. I tried the following code but line3 gives an error:

'get selected item in listbox1 to add to listbox2
lstDeck.AddItem lstAllCards.Text

'get the index of item just added (is this wrong?)
theIndex3 = lstDeck.ListIndex

'select item just added with the index value I obtained (error occurs here)
lstDeck.Selected(theIndex3) = True

I tried to used the following and it works in selecting the first entry but I don't want the first item to be selected. I want whatever item I just added to be the one selected:

lstDeck.Selected(0) = True

Any help would really be appreciated. Thank you in advance.

How To Determine Listbox Not Selected Yet??
i have a problem. i have two lists and one command button on form1 and each list have five items. i want that if one of both or both lists not clicked
(means not select any item from list or lists or from both lists) then command1 not executed otherwise it show form2 what the code is

Selected Elements At The Top Of A Listbox?
Hello, I want to do multiselection on a list box with many items. My pourpose is to see at the top of the list box the selected elements when finish the selection. I'm using a curious custom listbox that automaticaly expands at get focus.
Can you help me please?
Thank you very much

here's the code I use
(put a listbox and a timer "tmrWait")
Option Explicit

Private Sub Form_Load()
tmrWait.Interval = 50
tmrWait.Enabled = False

List1.AddItem "cat"
List1.AddItem "dog"
List1.AddItem "horse"
List1.AddItem "elephant"
List1.AddItem "lion"
List1.AddItem "panda"
List1.Height = 120
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

With List1
If X < .Left Or X > .Left + .Width Or Y < .Top Or Y > .Top + .Height Then
.Height = 120
tmrWait.Enabled = False
End If
End With
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
tmrWait.Enabled = True
End Sub

Private Sub tmrWait_Timer()
List1.Height = 2000
End Sub

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

Copyright 2005-08, All rights reserved