Jump to content

Combobox search key choice ?


Efo74
 Share

Recommended Posts

Hello Autoit People , I don't know if it is possible to solve this problem with a combobox control. In the example I entered, I made a combobox with the following elements AItem 1 | BItem 2 | CItem 3 | DItem 4. During use, the user can expand the control and ... by pressing for example the letter C, it will automatically move to the CItem 3 line ... pressing B to the BItem 2 line and so on. I would like to know if it is possible to change this behavior and allow to press for example 2 to go to the BItem 2 line ... press 4 to go to the DItem4 line. I would like to be able to choose which font to start with for the quick search. In this case, instead of starting from the first character, I would like it to start from character 7. Is it possible somehow ??

Thanks for the support.

code:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Example()

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example", 300, 200)

    ; Create a combobox control.
    Local $idComboBox = GUICtrlCreateCombo("AItem 1", 10, 10, 185, 20,$CBS_DROPDOWNLIST+$WS_VSCROLL)
    Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

    ; Add additional items to the combobox.
    GUICtrlSetData($idComboBox, "BItem 2|CItem 3|DItem 4", "EItem 2")

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    Local $sComboRead = ""

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop

            Case $idComboBox
                $sComboRead = GUICtrlRead($idComboBox)
                MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

:rolleyes:

Link to comment
Share on other sites

It's probably possible other ways, but the simplest would seem to be to re-name your items to look like "1 - AItem 1". Then, when you need the value, remove the first 4 characters with StringTrimLeft($sValue, 4)

If that doesn't work for you, you could look into using GUISetAccelerators, though that would activate the ComboBox item regardless of where you select on the GUI

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Here a way you could do it :

#include <GUIConstants.au3>
#include <GuiComboBox.au3>
#include <Constants.au3>

Example()

Func Example()
  ; Create a GUI with various controls.
  Local $hGUI = GUICreate("Example", 300, 200)

  ; Create a combobox control.
  Global $idComboBox = GUICtrlCreateCombo("AItem 1", 10, 10, 185, 20)
  Local $idButton_Close = GUICtrlCreateButton("Close", 210, 170, 85, 25)

  ; Add additional items to the combobox.
  GUICtrlSetData($idComboBox, "BItem 2|CItem 3|DItem 4", "EItem 2")
  GUISetState()
  GUIRegisterMsg($WM_COMMAND, WM_COMMAND)

  Local $sComboRead = ""

  ; Loop until the user exits.
  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE, $idButton_Close
        ExitLoop
      Case $idComboBox
        $sComboRead = GUICtrlRead($idComboBox)
        MsgBox($MB_SYSTEMMODAL, "", "The combobox is currently displaying: " & $sComboRead, 0, $hGUI)
    EndSwitch
  WEnd
EndFunc   ;==>Example

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
  Local $iIDFrom = _WinAPI_LoWord($iwParam), $iCode = _WinAPI_HiWord($iwParam)
  Local $sText, $sInd
  If $iIDFrom = $idComboBox Then
    If $iCode = $CBN_EDITCHANGE Then
      $sInd = _GUICtrlComboBox_GetEditText($idComboBox)
      For $i = 0 To _GUICtrlComboBox_GetCount($idComboBox) - 1
        _GUICtrlComboBox_GetLBText($idComboBox, $i, $sText)
        If StringInStr($sText, $sInd) Then
          _GUICtrlComboBox_SetCurSel($idComboBox, $i)
          ExitLoop
        EndIf
      Next
    EndIf
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

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...