|
-
Jun 16th, 2010, 10:43 AM
#1
Thread Starter
Junior Member
combo boxes
Hi people
ive got several combo boxs on a search form and its all working great if you select the items from the list, but have a problem if you type the value, the selectedvalue isnt being returned
what do i need to do, this is what im using to get the value when selecting via clicking
Private Sub BTYPE_ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTYPE_ComboBox.SelectedIndexChanged
If Len(Trim(BTYPE_ComboBox.Text)) > 0 Then BTYPE_FILTER.Text = BTYPE_ComboBox.SelectedValue.ToString Else BTYPE_FILTER.Text = 0
End Sub
many thanks
-
Jun 16th, 2010, 11:19 AM
#2
Re: combo boxes
Moved to VB.NET From Database Development As The Question Is More VB Related
Run the same code in the Keypress is the <Enter> key is pressed after they have finished typing.
Alternately, don't allow them to type anything into the combo box.
-
Jun 16th, 2010, 07:12 PM
#3
Re: combo boxes
Using SelectedValue in a ComboBox that accepts direct input doesn't make sense. If you type something in then you haven't selected anything. You should be using Text, not SelectedValue.
-
Jun 17th, 2010, 01:31 AM
#4
Thread Starter
Junior Member
Re: combo boxes
Hi sorry my fault should of explained better
the data in the combobox has a numeric value and the display value i.e 98 PUB
all im after is if they start to type for example pub it then finds that from the list and then validates it to return the value 98
thanks
-
Jun 17th, 2010, 01:51 AM
#5
Re: combo boxes
If you want the user to have to select an item from the list then you should set the DropDownStyle to DropDownList.
-
Jun 17th, 2010, 03:16 AM
#6
Thread Starter
Junior Member
Re: combo boxes
hi that nearly does what i want only think is it doesnt match as you type it only matches the first letter ie the P
can you make accept more text as we have alot of different names being able to filter the list more by typing part of the name in really speeds things up, the system was written before in MS access and there comboboxes can do this
thanks
-
Jun 17th, 2010, 03:47 AM
#7
Re: combo boxes
You're going to have to write some code then. You can use the auto-complete functionality built into the control to help but you're going to have to manually select the corresponding item when the user types in a value rather than selecting it from the drop-down list. Note that the control's drop-down list and the auto-complete list are two different things. Also, you'll need to consider what happens if the user types a value that doesn't match an item or matches multiple items.
-
Jun 24th, 2010, 07:04 AM
#8
Thread Starter
Junior Member
Re: combo boxes
hi do you have any sample code to get me started as im rather stuck
-
Jun 24th, 2010, 07:24 AM
#9
Re: combo boxes
Handle the Validating event, get the Text, find a matching item and select it. If there is no matching item then you'd probably want to set e.Cancel to True to prevent the control losing focus.
-
Jun 24th, 2010, 09:56 AM
#10
Thread Starter
Junior Member
Re: combo boxes
i final found my problem, my data had extra space after it from where i had import from a old database, the combo box is now working great
many thanks for the help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|