Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple combo doubt

Status
Not open for further replies.

shanmugham

Programmer
Jun 19, 2001
71
IN
i have a combo with list of names are

Shanmugham
Ramalingam
Murugam
Siva
Sivalingam
Muruganandham

just i type the letter S immediatly combo select the name Shanmugham (automatically come that name on the combo box)

next i type Si immediatly selct the name Siva

how can i do this in combo


shan

 
Try changing the combo box style to '1 - Simple Combo' and increasing the height.

Hope this helps --------------------------------
If it ain't broke, don't fix it!
 
thanks

it does not select, it only comes first position

i want to select and it comes automatically in the combo
selection area.
pl help..
shan
 
Much as I hate posting chunks of code, this seems to answer the question exactly

This is swagged direct from the vb newsletter from
SELECT ENTRIES QUICKLY IN A DROP-DOWN COMBO BOX

In combo boxes with many entries, the user often needs a way to quickly pick an entry. One way to accomplish this in VB6 is to provide a combo box that selects entries as the user types letters. This allows the user to narrow the list of items that they need to search.

To implement this, use the SendMessage API call and the CB_FINDSTRING message. First, place a combo box on a form. Set the style to 0--Dropdown Combo. Then add the following to the declarations section of the form:

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const CB_FINDSTRING = &H14C

Add the following code to the Form_Load event to populate the combo box:

Call Combo1.AddItem("Baker")
Call Combo1.AddItem("Barber")
Call Combo1.AddItem("Barker")
Call Combo1.AddItem("Berkley")
Call Combo1.AddItem("Brown")
Call Combo1.AddItem("Carter")
Call Combo1.AddItem("Davis")

Next, add the following code to the Combo1_KeyPress event:

Dim lngRow As Long
Dim strSearchText As String

'Only process key if it is a character
If KeyAscii < 32 Or KeyAscii > 127 Then
Exit Sub
End If

If Combo1.SelLength = 0 Then
strSearchText = Combo1.Text
Else
strSearchText = Left(Combo1.Text, Combo1.SelStart)
End If
strSearchText = strSearchText & Chr(KeyAscii)

lngRow = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal
strSearchText)

If lngRow > -1 Then
Combo1.ListIndex = lngRow
Combo1.SelStart = Len(strSearchText)
Combo1.SelLength = Len(Combo1.Text) - Combo1.SelStart
End If
KeyAscii = 0

This code gets the current text from the combo box based on the selected text. It then calls the SendMessage API call, passing the hWnd of the combo box, the CB_FINDSTRING constant, -1 (to indicate that all rows should be searched), and the text to find. The return is the index of the matching row, or -1 if there was an error.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
thanks for your help

during the run time the error shows the following line

lngRow = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal
strSearchText)

error mesg are &quot;Runtime Error49
bad DLL Calling convention&quot;

i think a small error..
pl hel me
thanks in advance
shan


 
This bit:
lngRow = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal
strSearchText)

should all be on one line:
lngRow = SendMessage(Combo1.hwnd, CB_FINDSTRING, -1, ByVal strSearchText)
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
It works for me as posted. Are you using VB6 with SP5?
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 

This code:

If Combo1.SelLength = 0 Then

Doesn't this always return zero in the combo keypress?

 
i am using vb6.0 with access 97,

i tried, same error continues, this is very urgent pls

pl help me
shan

 
I ask again - Are you using Service Pack 5?

If not, then do the update available from:


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
i am using visual basic 6.0 enterprise edition

access 97

pl help me
shan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top