Jump to content

Predictive Combo Box


Jewtus
 Share

Recommended Posts

I am trying to figure out what the best way of doing this is. I have several combo boxes that changed based on the previous combo box selection. I'd like to setup the ability to automatically predict the combo box input if you start typing.

For example:

Combo1 has the options for Yes|No|Maybe|So

If Yes is selected

Combo2 has This|Is|A|Test

If no is selected

Combo2 has Test|A|Is|This

I'd like to make it so If I hit Y on the first combo box, it automatically predicts Yes and when I hit TAB, combo box 2 is updated with the Yes selection.

I found this UDF:

'?do=embed' frameborder='0' data-embedContent>>

But it is for an edit control and uses a dictionary.

Is there a way to predict text in the combobox based on what its data is already set to?

Link to comment
Share on other sites

  • Moderators

Jewtus,

You need to use _GUICtrlComboBox_AutoComplete like this: :)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>

Global $array_1[10] = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"]
Global $array_2[5] = ["alpha", "beta", "gamma", "delta", "epsilon"]

$hGUI = GUICreate("Example", 500, 200)

$cCombo_Number = GUICtrlCreateCombo("", 50, 50, 200, 20)
$cCombo_Alpha = GUICtrlCreateCombo("", 50, 100, 200, 20)
$a = ""
For $i = 0 To UBound($array_1) - 1
    $a &= $array_1[$i] & "|"
Next
GUICtrlSetData($cCombo_Number, $a)
$a = ""
For $i = 0 To UBound($array_2) - 1
    $a &= $array_2[$i] & "|"
Next
GUICtrlSetData($cCombo_Alpha, $a)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Edit_Changed($hControl)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hControl)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $cCombo_Number
                    _Edit_Changed($cCombo_Number) ; <<<<<<<<<<<<<<<<<<<<<
                Case $cCombo_Alpha
                    _Edit_Changed($cCombo_Alpha) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ok, I got this to work, but I'm having some issues...

(probably because I don't get how a lot of these examples Melba posts work... but I'm always able to get them functional in my scripts)

Func _Edit_Changed($hControl)  ; <<<<<<<<<<<<<<<<<<<<<
    _GUICtrlComboBox_AutoComplete($hControl)  ; <<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>_Edit_Changed

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $BL
                    _Edit_Changed($BL) ; <<<<<<<<<<<<<<<<<<<<<
                Case $Issue
                    _Edit_Changed($Issue) ; <<<<<<<<<<<<<<<<<<<<<
                Case $IssueDescript
                    _Edit_Changed($IssueDescript) ; <<<<<<<<<<<<<<<<<<<<<
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

This is what I used and it does exactly what I want it to do with one caveat... I have sqlite query that updates the next entry box that doesn't seem to be working when I use the auto complete.

EX:


Case $BL
                $IssueList = GetRecords($sqlDB,"SELECT b.Description FROM LKUP_BusinessLine a join LKUP_Issue b on a.id=b.ClassID where a.Description='"&GUICtrlRead($BL)&"';")
                $stage = ''
                For $z=1 to UBound($IssueList) -1
                    $stage = $stage&"|"&$IssueList[$z][0]
                Next
                GUICtrlSetData($Issue,$stage)
            Case $Issue
                $IssueDescriptList = GetRecords($sqlDB,"SELECT b.Description FROM LKUP_Issue a join LKUP_IssueDescriptions b on a.issueid=b.issueID where a.Description='"&GUICtrlRead($Issue)&"';")
                $stage = ''
                For $z=1 to UBound($IssueDescriptList) -1
                    $stage = $stage&"|"&$IssueDescriptList[$z][0]
                Next
                GUICtrlSetData($IssueDescript,$stage) 

I'm not exactly sure how to mash these two functions together. 

I don't want the sqlite query to happen every single time I type a letter, just when I exit the combo box (to move to the next combo box).

Link to comment
Share on other sites

  • Moderators

Jewtus,

 

because I don't get how a lot of these examples Melba posts work

Never be afraid to ask - I am always happy to explain. :)

 

just when I exit the combo box

If I have understood you correctly, you need to look for the $CBN_KILLFOCUS message from the second combo and only then load the third combo:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIComboBox.au3>

Global $array_1[5] = ["one", "two", "three", "four", "five"]
Global $array_2[5] = ["alpha", "beta", "gamma", "delta", "epsilon"]
Global $array_3[5] = ["tom", "dick", "harry", "bob", "alice"]

$hGUI = GUICreate("Example", 500, 200)

$cCombo_Number = GUICtrlCreateCombo("", 10, 10, 200, 20)
$cCombo_Alpha = GUICtrlCreateCombo("", 10, 50, 200, 20)
$cCombo_Name = GUICtrlCreateCombo("", 10, 90, 200, 20)

Local $a = "", $b = "", $c = ""
For $i = 0 To UBound($array_1) - 1
    $a &= $array_1[$i] & "|"
    $b &= $array_2[$i] & "|"
    $c &= $array_3[$i] & "|"
Next
GUICtrlSetData($cCombo_Number, $a)
GUICtrlSetData($cCombo_Alpha, $b)

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Edit_Changed($hControl)
    _GUICtrlComboBox_AutoComplete($hControl)
EndFunc   ;==>_Edit_Changed

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iwParam, 16) ; Hi Word
    Switch $iCode
        Case $CBN_EDITCHANGE
            Switch $iIDFrom
                Case $cCombo_Number
                    _Edit_Changed($cCombo_Number)
                Case $cCombo_Alpha
                    _Edit_Changed($cCombo_Alpha)
            EndSwitch
        Case $CBN_KILLFOCUS ; Second combo has lost focus...
            Switch $iIDFrom
                Case $cCombo_Alpha
                    GUICtrlSetData($cCombo_Name, $c) ; ...so load third combo
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND
As you can see, the third combo is empty until you have given and then removed focus from the second. This way you will never run the SQLite query until the second combo is complete. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Awesome! That is exactly what I needed. I'm leaving in the old case statements (in case I dont want to use the predictive text for some reason).

Everyone on here is so great!

Thanks fellas (especially Melba :thumbsup: )

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...