Sign in to follow this  
Followers 0
Spiff59

Prettier _GUICtrlComboBox_AutoComplete ?

1 post in this topic

I tweaked a couple lines in _GUICtrlComboBox_AutoComplete that I think makes it behave a little more intuitively.

Rather than it depending upon the selected portion of text, this version is driven by cursor position. {BACKSPACE} and {DEL} are no longer disabled and function somewhat as one would expect. Tell me what ya think.

Func _GUICtrlComboBox_AutoComplete($hWnd)
    Local $ret, $sInputText, $sEditText, $sEditSel
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)   
    $sEditSel = _GUICtrlComboBox_GetEditSel($hWnd)
    If IsArray($sEditSel) Then 
        $sEditSel = $sEditSel[0]
    EndIf
    $sEditText = StringLeft(_GUICtrlComboBox_GetEditText($hWnd), $sEditSel)
    _GUICtrlComboBox_SetEditText($hWnd, $sEditText)
    If StringLen($sEditText) Then
        $ret = _GUICtrlComboBox_FindString($hWnd, $sEditText)
        If ($ret <> $CB_ERR) Then
            _GUICtrlComboBox_SetCurSel($hWnd, $ret)
        EndIf
        _GUICtrlComboBox_SetEditSel($hWnd, $sEditSel, $sEditSel)
    EndIf
EndFunc  ;==>_GUICtrlComboBox_AutoComplete

I do think there's room for improvement in the way that the left, right, up and down keys are handled, and it would be nice if an unsuccessful search could leave a file-pointer or cursor (a 'cursor' of the DB2 variety) so that the drop down would be positioned at the next record/row in the list. For instance, a NOTFND on "Azzz" would position the list at the first "b" record. But either of those changes would add a lot of code to the function, whereas this mainly cosmetic change is actually a couple lines shorter.

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0