FrancescoDiMuro

Add element in a ComboBox if it's not in the ComboBox data

3 posts in this topic

#1 ·  Posted (edited)

Good morning :)

I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:

- Form with some data ( ComboBox is empty );

- User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.

More pratical example:

- First call of the form, ComboBox empty;

- I prompt "A" in the ComboBox;

- Second call, in the ComboBox I should see "A";

- I prompt "B" in the ComboBox;

- Third call, I should see "A"
                                           "B";

- And so on...

Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().

I tried with

Global $strCboStrings = ""

; When the user prompt the form, the code below is executed.
; I.E. : User prompt "A", after the if I should have "A";
; In the second call, If I write "B", I should see "A"
;                                                  "B";
; If I write "A" again, in the combobox values should not be any changes.

If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then
    $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory)
EndIf

Any suggestion?

Thanks :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

Share this post


Link to post
Share on other sites



FrancescoDiMuro,

I would do something like this:

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

; Create a Global variable to hold the combo data
Global $sComboData = ""
; Create placeholders for the child GUI and controls
Global $hChild = 9999, $cCombo = 9999, $cAdd = 9999

; Create main GUI
$hGUI = GUICreate("Test", 500, 500)

; You say you recreate the combo each time, so this will do just that
$cAction = GUICtrlCreateButton("Action", 10, 10, 80, 30)

GUISetState()

While 1

    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $cAction
                    ; Create a child GUI
                    _CreateChild()
            EndSwitch
        Case $hChild
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    ; Close the child GUI
                    GUIDelete($hChild)
                Case $cAdd
                    ; Add new data to the combo
                    _AddComboData()
                Case $cCombo
                    ; Just to show that the data is selectable
                    MsgBox($MB_SYSTEMMODAL, "Selected", GUICtrlRead($cCombo))
            EndSwitch
    EndSwitch

WEnd

Func _CreateChild()

    ; Create child GUI
    $hChild = GUICreate("Child", 250, 250, -1, -1, $GUI_SS_DEFAULT_GUI)
    ; Create combo and load with saved data
    $cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
    GUICtrlSetData($cCombo, $sComboData)
    ; Create a button to add new data
    $cAdd = GUICtrlCreateButton("Add", 10, 50, 80, 30)

    GUISetState()

EndFunc

Func _AddComboData()

    ; Read the content of the combo edit
    $sComboSel = GUICtrlRead($cCombo)
    ; Check if in saved data
    If Not StringInStr($sComboData, "|" & $sComboSel) Then
        ; If not then add to saved data and load into the combo
        $sComboData &= "|" & $sComboSel
        GUICtrlSetData($cCombo, $sComboData)
    EndIf

EndFunc

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

Thanks for you help!

I was missing this part

$cCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($cCombo, $sComboData) ; ---------------------------> This one!

Thanks a lot!

Have a good day :)

Francesco

 


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hi guys
      I have an inquiry please
      I want an example of how to add an icon file to the compiled autoit file and how to use it in GUICtrlCreateIcon
      Preferably in a separate list within the resourceFor example myIcons
      I hope my request is clear and I hope you will help me solve this problem
      Because I found an example in the help files but I did not understand the method well
    • kstriyhon
      By kstriyhon
      hello Comunity i am new to autoit and i bump into a pitfall regarding the creation of objects in a dinamyc way but more especific  creating combobox at runtime
      i need many comboboxes and sofar i createdthem manually 
      like this 
      $idCombo_1 = GUICtrlCreateCombo("", 500, 40, 130, 21)     $idCombo_2 = GUICtrlCreateCombo("", 500, 70, 130, 21)     $idCombo_3 = GUICtrlCreateCombo("", 500, 100, 130, 21)     $idCombo_4 = GUICtrlCreateCombo("", 500, 130, 130, 21)     $idCombo_5 = GUICtrlCreateCombo("", 500, 160, 130, 21)     $idCombo_6 = GUICtrlCreateCombo("", 500, 190, 130, 21)     $idCombo_7 = GUICtrlCreateCombo("", 500, 220, 130, 21)     $idCombo_8 = GUICtrlCreateCombo("", 500, 250, 130, 21)     $idCombo_9 = GUICtrlCreateCombo("", 500, 280, 130, 21)     GUICtrlSetData($idCombo_1, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_2, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_3, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_4, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_5, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_6, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_7, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_8, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_9, "Item1|Item2|Item3|Item4|Item5") now i need this example but create them at runtime as there are more than 9 combos what i need thanks in advance kind regards
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening guys
      I am working on a little project, in which I have to retrieve 8000+ rows of data from a table, from a SQLite database, to populate a combobox 
      This is what I tried 'til now, but it still takes about 12 seconds to populate the combobox.
      _SQLite_Exec($objDatabase, "BEGIN TRANSACTION;") If _SQLite_GetTable($objDatabase, "SELECT DISTINCT Comune FROM LISTA_COMUNI;", $arrRisultatoQuery, $intRighe, $intColonne) = $SQLITE_OK Then For $i = 2 To UBound($arrRisultatoQuery) - 1 If $i < UBound($arrRisultatoQuery) - 1 Then GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i] & "|") Else GUICtrlSetData($cbo_ComuneNascita, $arrRisultatoQuery[$i]) EndIf Next _SQLite_Exec($objDatabase, "COMMIT;") Are there any other solution to retrieve 8000+ records from a SQLite database?
      Thank you very much  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning community!
      I am working on a script which read from a text file ( .txt ) and should import all the content in a SQLite3 DB, in order to execute some queries that should be difficult to execute on a text file.
      So, I was looking for something very very fast, because the file could be very large ( I don't know exaclty how much can became big, but I know a lot of rows, it's a log file ... )
      I found the "Import method", but I don't know If I can implement it in a query ( @jchd, it's your turn!  )
      Do you know some methods that I can implement in my script to have a very very fast import of thousands and thousands rows in a SQLite3 DB?
      Thanks a lot
      Francesco
    • bdenn
      By bdenn
      Hello,
      I have searched and searched the web for an answer on how to get data from a webpage and paste it into a notepad document.
      The problem is I need to access a website that is not on the internet but yet only on our local network so the IP will be "192.168.125.xxx"
      This site only displays a few things but what I need to do is pull two parts of information that are located in a table. looking at this as an excel point of view this would be cells B2 and C2. These cells hold two numbers that say 850 Watts and 3 Watts, but they change all the time.
      If I do a page "inspect element" I can see these exact numbers in the source code but very deep.
      Currently I have the following code:
      run ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")         sleep(500)         Send("192.168.125.xxx")         Send("{Enter}")         sleep(100)         Send("password")         Send("{Enter}") How do I get AutoIT to see these two data points and copy and paste them into a notepad.
      I do not really need the webpage to open, but will deal with it if I need to.
      ** I have attached an image of the data I need.
      Thanks,
      Bdenn