|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Automatically selecting text in a ComboBox Dropdown List
I created a combo box with the Dropdown List style property because I essentially want to restrict the user to enter only specified items.
I use the following code to select specific text in a combo box but it seems like there is a better way. This method is slow and you can see the combo box scroll through the items on a slow computer. Any help is appreciated. Thanks in advance for you time! Code:
Public Function GetPC(ByVal strText As String) As Integer Dim i As Integer With frmMain.cboPriority For i = 0 To .ListCount .ListIndex = i If .Text = strText Then GetPC = i Exit Function End If Next i End With End Function I use the following code to call this function... Code:
cboPriority.ListIndex = GetPC(rstAccounts!PC) I tried to write to the .Text property of the list box hoping that it would select the item matching the text I specify but it gives me a run-time error. I found that I can only read the .Text propery at run-time when the Dropdown list style is used. Thanks, Luke |
|
#2
|
|||
|
|||
|
Hi,
There is one quick solution for your problem. There is also a more extensive solution, that encourages reuse of the combobox acros multiple forms (or even projects). But I take it you want the short quick solution. Try the following code: Code:
lResult = winSendMessageS(cboCombobox.hwnd, CB_FINDSTRING, -1, "Text to find") cboCombobox.Listindex = lResult This is an api call that will tell the combobox to look in its contents for the string. Below are the declarations for the api calls: Code:
Public Declare Function winSendMessageS Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As String) As Long Public Const CB_FINDSTRING = &H14C Public Const CB_FINDSTRINGEXACT = &H158 The CB_FINDSTRINGEXACT will cause the combobox to search case sensitive. The other CB_FINDSTRING does not care about case. If you want a better solution, you might make a usercontrol that contains the combobox and wrap the needed methods and properties in the usercontrol. If you want an example, I could post it here but it is alot of code. I use this solution for all my comboboxes I need in applications and reuse existing ones when I need the same combobox in another program. But that is entirely up to you. The Api call works just as well. If you have any questions, feel free to ask them. Grtz.© M. |
|
#3
|
|||
|
|||
|
Thanks for the reply! Much appreciated.
-Luke |
|
#4
|
|||
|
|||
|
Quote:
hi all, I have a similar problem with combo boxes. I want to dynamically link more than 2 combo boxes, i.e. when i change a selection in one combobox, the 2nd combobox gives a corresponding list, and when i change selection in the 2nd combobox, the third box gives another corresponding list. any ideas on this? ![]() |
|
#5
|
|||
|
|||
|
Don't add to a long-dead thread, post your own question topic.
Look at the onChange or lostFocus events to fire code that changes other combo lists.
__________________
====== Doug G ====== I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Automatically selecting text in a ComboBox Dropdown List |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|