Jump to content
Sign in to follow this  
Golabius

[Solved] help: ComboBox without dropdown button

Recommended Posts

Golabius

pls help me!

how can i create comboBox without dropdown button?(and need dropdown list after type anything but dont need dropdown button.)

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

$Form = GUICreate("comboBox without dropdown button", 413, 298)
$Combo1 = GUICtrlCreateCombo("", 136, 98, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "s1|s2|s3|s4|s5|s6", "s1")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by Golabius

Share this post


Link to post
Share on other sites
Syed23

quote name='Golabius' timestamp='1310992893' post='911436']

pls help me!

how can i create comboBox without dropdown button?(and need dropdown list after type anything but dont need dropdown button.)

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

$Form = GUICreate("comboBox without dropdown button", 413, 298)
$Combo1 = GUICtrlCreateCombo("", 136, 98, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "s1|s2|s3|s4|s5|s6", "s1")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Golabius

Syed23, tnx but i dont want it.

see this fake picture:

Posted Image

i want create autocomplete with combobox and without dropdown button.

(i dont want combin TextBox + ListBox For it.)

and i dont want like it:

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()
    Local $hGUI, $hImage, $hCombo
    
    ; Create GUI
    $hGUI = GUICreate("ComboBoxEx Reset Content", 400, 300)
    $hCombo = _GUICtrlComboBoxEx_Create ($hGUI, "", 2, 2, 394, 100, BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER))
    GUISetState()
    
    _GUICtrlComboBoxEx_BeginUpdate ($hCombo)
    For $x = 0 To 149
        _GUICtrlComboBoxEx_AddString ($hCombo, StringFormat("%03d : Random string", Random(1, 100, 1)), Random(0, 8, 1), Random(0, 8, 1), Random(0, 8, 1))
    Next
    _GUICtrlComboBoxEx_EndUpdate ($hCombo)

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

i just want hide comboBox dropdown button. :)

Share this post


Link to post
Share on other sites
czardas

If you don't want the dropdown, then perhaps using a combobox is not the solution. You want a single line edit control that autocompletes from list of strings. Maybe there is a simpler solution: hopefully someone will suggest one. Failing that, you could try to design a control that mimicks combobox behaviour. I pressume you want to be able to use the arrow keys to scroll through the list, as well as implementing an autocomplete feature. It will require some further thought.

Share this post


Link to post
Share on other sites
Melba23

Golabius,

I think this is close to what you want: ;)

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

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

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Test", 500, 500)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 25, 190, 20, BitOR(0x00100000, 0x00200000))
GUICtrlSetState(-1, $GUI_HIDE)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            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 CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $iLine_Height = _GUICtrlListBox_GetItemHeight(GUICtrlGetHandle($hList))
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        $iMatch_Count = 0
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then
                $sPartialData &= $asKeyWords[$i] & "|"
                $iMatch_Count += 1
            EndIf
        Next
        GUICtrlSetData($hList, $sPartialData)
        ConsoleWrite("Matches: " & $iMatch_Count & " - List Height: " & $iMatch_Count * ($iLine_Height + 1) & @CRLF)
        If $iMatch_Count Then
            $iLine_Height = _GUICtrlListBox_GetItemHeight(GUICtrlGetHandle($hList))
            GUICtrlSetState($hList, $GUI_SHOW)
            $iList_Height = $iMatch_Count * ($iLine_Height + 2)
            If $iList_Height > 100 Then $iList_Height = 100
            If $iList_Height < $iLine_Height + 6 Then $iList_Height = $iLine_Height + 6
            ConsoleWrite("Adjusted: " & $iList_Height & @CRLF)
            GUICtrlSetPos($hList, 5, 25, 190, $iList_Height)
        Else
            GUICtrlSetState($hList, $GUI_HIDE)
        EndIf
    Else
        GUICtrlSetState($hList, $GUI_HIDE)
    EndIf
EndFunc   ;==>CheckInputText

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)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

Please ask if you have any questions or if it is not quite what you are looking for - it should be fairly easy to tweak. :)

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
Golabius

Melba23, very nice & very tnx but:

...

i want create autocomplete with combobox and without dropdown button.

(i dont want combin TextBox + ListBox For it.)

...

i have some button under this list box and ...

i dont want DISABLE and ENABLE listbox(button) for work button(listbox) or help me in Z-Index(depth) for create button on list box.

i can create it with do resize comboBox in simple style but im looking a way for hide dropdown button just. its possible?

Share this post


Link to post
Share on other sites
Melba23

Golabius,

its possible?

As far as I know it is not - whch is why I gave you another solution. :)

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
Golabius

Melba23, tnx again and can u help me about controls Z-Index(depth) for create button on listBox(EditBox)?

Simple Code:(Button Doesn't work)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form = GUICreate("Form", 413, 298, 229, 156)
$Edit = GUICtrlCreateEdit("", 2, 2, 307, 193)
$Button = GUICtrlCreateButton("Button", 204, 138, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

My COde:(i Dont want like it,DISABLE & ENABLE)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$over = 0

$Form = GUICreate("Form", 413, 298, 229, 156)
$Edit = GUICtrlCreateEdit("", 2, 2, 307, 193)
$Button = GUICtrlCreateButton("Button", 204, 138, 75, 25)
GUISetState(@SW_SHOW)


While 1
    $info = GUIGetCursorInfo()
    if not @error Then
        If ($info[4]=$Button) Then
            If ($over = 0) Then
                $over = 1
                GUICtrlSetState($Edit,$GUI_DISABLE)
            EndIf
        Else
            If $over = 1 Then 
                $over = 0
                GUICtrlSetState($Edit,$GUI_ENABLE)
            EndIf
        EndIf
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by Golabius

Share this post


Link to post
Share on other sites
Melba23

Golabius,

If you want overlapping controls then I fear you are going to have to use something like your second example. ;)

AutoIt (and Windows) cannot cope with overlapping controls - after all, your PC cannot read your mind as to which control you want to action. :)

Why are you so against the enabling/disabling of the various controls? The only other way I can think of doing it would be to create a child GUI to hold the list - and I am not sure that it would be worth the trouble. But if I find a few minutes over the next few days (I am a bit busy in the wild blue yonder :D) I will see if I can produce anything less complicated that what you already have produced. ;)

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
Melba23

Golabius,

You were in luck - too rainy to fly this morning so I could work on this. But I did get airborne this afternoon, so I am still in a good mood! :)

Here is a version with a child GUI that gets over the "button underneath" problem - you still have to do a fair bit of coding to get the thing to work, but you will have to do that regardless of the solution you choose if you do not want a standard combo: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListBox.au3>

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

$hGUI = GUICreate("Example", 500, 500)
$hInput = GUICtrlCreateInput("", 10, 10, 200, 20)

$hButton = GUICtrlCreateButton("Test", 10, 50, 80, 30)

GUISetState(@SW_SHOW, $hGUI)

; Create chilf GUI to hold list
$hGUI_Child = GUICreate("Child", 200, 200, 10, 30, $WS_POPUP, $WS_EX_MDICHILD, $hGUI)
$hList = GUICtrlCreateList("", 0, 00, 200, 200, BitOR(0x00100000, 0x00200000))
GUICtrlSetResizing(-1, $GUI_DOCKAUTO) ; List resizes with GUI
GUISetState(@SW_HIDE, $hGUI_Child)

Keywords()

$sCurr_Input = ""
$sData = "|"
$sChosen = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
            GUISetState(@SW_HIDE, $hGUI_Child)
        Case $hButton
            ConsoleWrite("Button pressed" & @LF)
    EndSwitch

    ; Show/hide child GUI depending on input content and list data
    If GUICtrlRead($hInput) <> "" And GUICtrlRead($hInput) <> $sChosen And Not(BitAND(WinGetState($hGUI_Child), 2)) And $sData <> "|" Then
        GUISetState(@SW_SHOW, $hGUI_Child)
        GUICtrlSetState($hInput, $GUI_FOCUS)
        ControlSend($hGUI, "", $hInput, "{END}")
    EndIf
    If GUICtrlRead($hInput) = "" And BitAND(WinGetState($hGUI_Child), 2) Then
        GUISetState(@SW_HIDE, $hGUI_Child)
        GUICtrlSetState($hInput, $GUI_FOCUS)
    EndIf

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

WEnd

Func Keywords()

    ; Only items beginning with B created - so able to see what happens when list holds nothing (hides) or lots of data (scrolls)
    For $i = 0 To 99
        $asKeyWords[$i] = "B" & Chr(Random(65, 90, 1)) & 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))
    $sData = "|" ; Start with delimiter so new data always replaces aold
    Local $sInput = GUICtrlRead($hInput)
    $iMatch_Count = 0
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringLeft($asKeyWords[$i], $l) = $sInput Then
                $sData &= $asKeyWords[$i] & "|"
                $iMatch_Count += 1
            EndIf
        Next
        GUICtrlSetData($hList, $sData)

        ; Change size of child GUI
        $iList_Height = $iMatch_Count * (_GUICtrlListBox_GetItemHeight($hList) + 1)
        If $iList_Height < 20 Then $iList_Height = 20
        If $iList_Height > 200 Then $iList_Height = 200

        WinMove($hGUI_Child, "", Default, Default, Default, $iList_Height)

    EndIf
EndFunc   ;==>CheckInputText

Please ask if you have any questions, but I think it is pretty easy to follow. ;)

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
Golabius

Melba23,tnx. i think, this is the best way for create what i want, very tnx.

this is my simple code with comboBox(simple style) But still Melba23's way is better and more complete.

#include <GuiComboBoxEx.au3>
#include <GuiImageList.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$iY=20

_Main()

Func _Main()
    Global $hGUI, $hImage, $hCombo
    
    ; Create GUI
    $hGUI = GUICreate("ComboBox", 400, 300)
    $hCombo = GUICtrlCreateCombo ("", 2, 2, 394, $iY , BitOR($CBS_SIMPLE, $WS_VSCROLL, $WS_BORDER))
    GUICtrlSetData(-1, "B1|B2|B3|B4|B5")
    GUISetState()
    
    
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>_Main

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg
    Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
    If Not IsHWnd($hCombo) Then $hWndCombo = GUICtrlGetHandle($hCombo)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF) 
    $iCode = BitShift($iwParam, 16) 
    Switch $hWndFrom
        Case $hCombo, $hWndCombo
            Switch $iCode
            Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box
                    $combo_text = _GUICtrlComboBox_GetEditText($hCombo)
                    If (Not StringIsSpace($combo_text)) And $combo_text<>"" Then
                        iCombo_Resize(1)
                    Else
                        iCombo_Resize(0)
                    EndIf
                    
                    ; no return value
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>

Func iCombo_Resize($flag) ; Flag=1(Show List), else flag(Hide List)
    $iY =20
    If $flag=1 Then
        $count = _GUICtrlComboBox_GetCount($hCombo)
        For $i=1 to $count
            $iY +=15
        Next
    EndIf
    GUICtrlSetPos($hCombo,2, 2, 394, $iY)
EndFunc

Share this post


Link to post
Share on other sites
Melba23

Golabius,

Glad I could help. :)

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  

×

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.