Sign in to follow this  
Followers 0
shornw

Combi Box

9 posts in this topic

Hi all

Is it possible to set up a combi box so that as the user types it selects from the choices in a list, so for example,

GUICreate("Options available", 200, 80)  ; will create a dialog box that when displayed is centered
    GUICtrlCreateLabel("Please select from the drop-down box", 10, 10)
    $cList = GUICtrlCreateCombo("User Selection", 20, 40, 80,20)
    GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple")

if the user typed 'B', Banana would be higlighted.

I dont really want users to be able to type free text.

Sorry if this is something obvious, but I've looked theough the help files and now Im even more confused

Thanks for looking, any assistance greatly appreciated.


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites



Try this...

#include <GUIConstantsEx.au3>
#include <ComboConstants.au3>

Opt('MustDeclareVars', 1)

Global $cList

Example()



Func Example()
    Local $msg
    GUICreate("My GUI combo", 200, 80)  ; will create a dialog box that when displayed is centered
    
    GUICtrlCreateLabel("Please select from the drop-down box", 10, 10)  
    $cList = GUICtrlCreateCombo("User Selection", 20, 40, 80, 20, $CBS_DROPDOWNLIST)
    GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple")

    GUISetState()

    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
EndFunc   ;==>Example

jfcby


Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Share this post


Link to post
Share on other sites

shornw,

There is a _GUICtrlComboBox_AutoComplete function - you have to open the combo and then start typing before the autocompletion begins. Here is a short demo: :blink:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>

$hGUI = GUICreate("AutoComplete Combo Demo", 300, 200)

$hCombo = GUICtrlCreateCombo("", 70, 75, 170, 20, $CBS_DROPDOWNLIST) ; the style makes the combo read-only
GUICtrlSetData(-1, "Apple|Banana|Cherry|Damson|Other", "Apple")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iIDFrom = BitAND($wParam, 0x0000FFFF)
    Local $iCode = BitShift($wParam, 16)

    Switch $iIDFrom
        Case $hCombo
            Switch $iCode
                Case $CBN_EDITCHANGE
                    _GUICtrlComboBox_AutoComplete($hCombo)
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

I also wrote this a while ago and it might perhaps be of interest. You start typing in the input box and the valid items in the data appear in the list below - clicking an item in the list puts it in the edit box. If no items match the typing, then no list is displayed. Pressing the button checks that a valid data item is in the input and shows a MsgBox. The data is a random list of 5 letter combinations at present, but that is not difficult to change:

#include <GUIConstantsEx.au3>
#include <Array.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
GUISetState(@SW_SHOW, $hGUI)

$sCurr_Input = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)

EndFunc   ;==>Keywords

Func CheckInputText()
    $l = StringLen(GUICtrlRead($hInput))
    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringLeft($asKeyWords[$i], $l) = $sInput Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

If you are interested in this second option, let me know what (if anything :P ) needs changing. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Thanks for this.

Melba - I'll play around with it and see if I can make it work for me, Thanks for the code.

Does anyone know if there is a maximum number of items that can be used in a ComboBox. I have a large dept list, so I have pointed the GUICtrlSetData at a document:

$deplist = FileRead("C:\deplist.txt", 300)

GuiCtrlSetData($deplist, "Please Select")

but only 132 items appear.

Thanks again


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

shornw,

Read the Help file - the second parameter for FileRead is "the number of characters to read". So you are unlikely to read the whole list with just 300 chars. Use FileRead("C:\deplist.txt") and then you get the whole file. :blink:

I assume you store the delimiters in the file? ;)

M23

Edit: Added the delimiter part.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Right as usual Melba [sigh] :blink:

Now I have a new issue. If I include the $CBS_DROPDOWNLIST, I dont get a scrollbar and only a few items are listed. Any ideas, can I use multiple style items?

How difficult is it to use your code to read a text file?

Thanks


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

shornw,

I bet you created your combo like this: :

$cList = GUICtrlCreateCombo("User Selection", 20, 40, 80, 20, $CBS_DROPDOWNLIST)

Am I right? ;)

If so, then you have overwritten the default styles, which include a vertical scroll bar. Remember that if you define a style you overwrite any existing styles. So you have to restate all the existing styles that you want to retain. Look at this example:

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

$sData = ""
For $i = 1 To 100
    $sData &= $i & "|"
Next

$hGUI = GUICreate("Test", 500, 500)

$hCombo = GUICtrlCreateCombo("", 10, 10, 100, 20, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL, $WS_VSCROLL)) ; New style and old styles <<<<<<<<<<<
GUICtrlSetData($hCombo, $sData)

GUISetState()

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

All clear? :P

As to reading your file into my code, just replace function Keywords() with your file read code and it should work. :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

You are, of course, spot on. That was how I wrote the Combo, but in fairness it doesn't mention anywhere (obvious) in the help files....and I was on the right track with using multiple styles, so I'm not as embarrased as I might have been.

Thank you so much for your assistance which is equalled only by your patience.

As you may have guessed, I'm not a programmer :blink: but with your help I have a fully useable script.

PS I'd never even heard of BITor LOL


[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Share this post


Link to post
Share on other sites

shornw,

Thank you so much for your assistance

My pleasure. ;)

I'd never even heard of BITor

Try looking here if you want to know more about it - and why you should use it to combine styles. :blink:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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