RIAS
asked on
Select value from Listbox
Hello,
The listbox contains items like
REG 1NN
when I try to select or find the item in the listbox like 'REG1NN' it returns none as there is a space between G AND 1.
Thanks
The listbox contains items like
REG 1NN
when I try to select or find the item in the listbox like 'REG1NN' it returns none as there is a space between G AND 1.
.lstVehRegDailyRun.SelectedItem = Str_Car
Any suggestion on how can i search ignoring the space? Thanks
ASKER
Thanks Gustav Brock,
But, it didn't work. Any more suggestions?
Spec:
The item in listbox is with space.
The item in the textbox.text is without space.
But, it didn't work. Any more suggestions?
Spec:
The item in listbox is with space.
The item in the textbox.text is without space.
ASKER
Tried this as well
Dim index As Integer = .lstVehRegDailyRun.FindString(Str_Car)
' If the item was not found in ListBox 2 display a message box, otherwise select it in ListBox2.
If index = -1 Then
ClMain.FormatMessage(21, "Please check the Car's Reg as its not in the system. Please add the Car to the system.")
Exit Sub
Else
.lstVehRegDailyRun.SetSelected(index, True)
End If
We only had your single code line.
If you wish to match a string with the same string including a space, either the first must have a space inserted or the space must be removed from the last; or all spaces removed from both.
If you wish to match a string with the same string including a space, either the first must have a space inserted or the space must be removed from the last; or all spaces removed from both.
how are you getting Str_Car ?
This does work:
ListBox1.SelectedItem = "REG 1NN"
can you show the contents of str_car before trying to use it in the selectedvalue(msgbox or debug print)
This does work:
ListBox1.SelectedItem = "REG 1NN"
can you show the contents of str_car before trying to use it in the selectedvalue(msgbox or debug print)
ASKER
str_car is a string.
str_car = "REG1NN"
And the listbox items are
REG 1NN
REG 789
So it does exist in the listbox but, by the code ListBox1.SelectedItem it does not return true.
str_car = "REG1NN"
And the listbox items are
REG 1NN
REG 789
So it does exist in the listbox but, by the code ListBox1.SelectedItem it does not return true.
Also are you sure the "space" in "REG 1NN" is actually a space (chr(32)) , or some other non printable character?
ASKER
These values are coming from database.
it does not exist in the listbox, REG1NN is not the same as REG 1NN, it will never find it this way
so you can try to search only for a part of the string like
.lstVehRegDailyRun.Selecte dItem = left(Str_Car,3)
it will then give youthe first ocurrence of REG ignoring the rest
so you can try to search only for a part of the string like
.lstVehRegDailyRun.Selecte
it will then give youthe first ocurrence of REG ignoring the rest
ASKER
Could have done that but, its Car reg so finding just 1st three will not help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Arana (G.P.)
Trying and be right back
Trying and be right back
beware that this is not optimized for performance, if you have a lot of items in the list, this will not be fast (talking about hundreds of items)
ASKER
Thanks Arana (G.P.) it worked!
Open in new window