Jump to content
Sign in to follow this  

Prettier _GUICtrlComboBox_AutoComplete ?

Recommended Posts


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]
    $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)
        _GUICtrlComboBox_SetEditSel($hWnd, $sEditSel, $sEditSel)
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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.