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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoFill comboBox issue. Please Help!

Status
Not open for further replies.

jcm888

Programmer
Dec 13, 2004
1
0
0
US
Hi,
I am having a problem that I have spent literally dozens of hours on. Here is the scenario.

I am using VB6 comboBox that would have values as such:

1. ABC
2. BBB
3. BCC
4. CDE

I am automatically autofilling this, so if you typed a 'B', then 'BBB' would automatically fill in. Same if you typed 'BC', then 'BCC' would fill in. I am also using a timer that fires when you type a letter, since there is other backend data that is returned to populate other controls on my form. The returned data is based on what the user types (or chooses) in the combobox. I have tried dozens of different ways to get this to work, but my specific requirements are making this very very difficult to accomplish. THis is a prod. bug because users are quickly typing one or 2 letters and tabbing off to the next field. So when they save they might have saved the wrong value. Because if you very quickly typed 'BC' and tabbed off, VB is to slow in responding and will set selected index for 'BBB' instead of 'BCC'. I have tried putting the autofill logic in all diff. events: _KeyUp, _KeyDown, _Change with no luck. I believe the timers are adding a difficult dimension to this, because without them, i can get this to work, but the client insists on the use of timers to do backend querying the instant you type a letter in the field.
Any help would be greatly appreciated. This deals with
AutoFill combobox (combo box) and timers in VB6. All the autofill examples i see (via googling) are to simple for my needs or do not using timers. Is this a known issue with vb? I am thinking that when you have code in many events like keyup, change, keydown it just can't handle the quick processing neeeded. Does anyone know how to capture the buffer of keystrokes? Like i tried this for example:
public sub Combo1_KeyDown(nKeyCode%, nShift%)
Select Case nKeyCode
Case vbKeyDelete
m_bEditFromCode = True
mTimer.Enabled = False
mCbo.ListIndex = -1
Case vbKeyBack
m_bEditFromCode = True
m_bBackSpaceClicked = True
mTimer.Enabled = False
Case Else

strPartial= strPartial & Chr(nKeyCode)
End Select
'So then i kept track of letters typed in a variable (strPartial), but 'it is very difficult to keep the correct keystrokes 'in it since i have timers that raise the change event.
'So then i do this:
i = SendMessage2(.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
with mcbo
'If match found, append unmatched characters
If i <> CB_ERR Then
strTotal = .List(i)
j = Len(strTotal) - Len(strPartial) 'Compute number of unmatched characters
If j <> 0 Then
.Text = "" ' causes change event to fire
.ListIndex = mlIndex
.SelText = strTotal 'Right$(strTotal, j)
.SelStart = Len(strPartial) 'Select unmatched characters
.SelLength = j
Else
.ListIndex = i
.SelLength = 0
.SelStart = Len(strPartial)

End If
Else
'NO MATCH FOUND:

End If
end with
I tried putting this logic in _keyup and _change events, but VB automatically raises the _Change event when you do a .Text so then this logic gets executed like 3 times every time you type a letter in the combobox. I already tried exiting (or canceling) event using booleans, but it turns into spaghetti code trying to figure out which events should set bool to true or false. Is there a way to cancel an event from being raised?
thanks in advance! Sorry for the long text, but i wanted to be thorough in my explanation of my problem.
 
Well try this by using the window API

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Const LB_FINDSTRING = &H18F


List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, -1, ByVal List1.text)

U will have to play around with it.

Check out this website for help with Windows API :
 
Not sure if this will help. Might interfere with the autofill functionality. If it does you could mock up a combo box using a text tox and list box.

Code:
Private Sub Combo1_Change()
    
    'Do autofill here

    Combo1.Locked = True

    'Do query/display here...maybe a timer is not needed?

    Combo1.Locked = False
    'let the user type in another char    

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top