-
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
-
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.
-
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.
-
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
-
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.
-
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
-
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.
-
Re: combo boxes
hi do you have any sample code to get me started as im rather stuck
-
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.
-
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