Sign in to follow this  
Followers 0
myspacee

Request about _GUICtrlComboBox

5 posts in this topic

Hello,

i've populate a GUICtrlComboBox with a text file

______________________list.txt

67691
67692
67693
67694
67695
67697
67698
67699
67700
67701
67702
67704
67706
67707
67708
67709

design a gui with some buttons :

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)
#include <Array.au3>

dim $file, $line, $Button_ok, $Button_cancel, $msg
dim $avArray[1]
dim $hCombo


;////////////////////////////////////////////////////////////////////////
;       GUI
;////////////////////////////////////////////////////////////////////////
#Region ### START Koda GUI section ### Form=
GUICreate("ComboBox select from list", 396, 296)
;~ $_1 = GUICreate("ComboBox seleziona dalla lista", 247, 718, 393, 133)
$hCombo = GUICtrlCreateCombo("", 2, 60, 396, 296, BitOR($CBS_SIMPLE,$CBS_AUTOHSCROLL,$CBS_DISABLENOSCROLL,$WS_VSCROLL))
$Button_ok = GUICtrlCreateButton("OK", 16, 32, 81, 25, 0)
$Button_cancel = GUICtrlCreateButton("Cancel", 144, 32, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;////////////////////////////////////////////////////////////////////////
;       OPEN text file
;////////////////////////////////////////////////////////////////////////
$file = FileOpen("list.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf



;////////////////////////////////////////////////////////////////////////
;       populate COMBO
;////////////////////////////////////////////////////////////////////////

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop    

; Add files
    _GUICtrlComboBox_BeginUpdate($hCombo)
;~ ; Add string
    _GUICtrlComboBox_AddString($hCombo, $line)
;~ ; update
    _GUICtrlComboBox_EndUpdate($hCombo)
; select string
    _GUICtrlComboBox_SelectString($hCombo, "This")

Wend

FileClose($file)



;////////////////////////////////////////////////////////////////////////
;       GUI until user action
;////////////////////////////////////////////////////////////////////////
    
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button_ok
            msgbox(0,"","ok")
        Case $Button_cancel
            msgbox(0,"","cancel")
            ExitLoop
            
    EndSwitch
WEnd

GUIDelete()
msgbox(0,"","bye!")

i've some requests:

- when user select an item, item go in a variable, and must disappear from list

- refresh list

- auto select next item

Anyone can help me ?

Thank you,

m.

Share this post


Link to post
Share on other sites



#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIComboBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Opt('MustDeclareVars', 1)
#include <Array.au3>

dim $file, $line, $Button_ok, $Button_cancel, $msg, $SelectedText, $SelectedItem
dim $avArray[1]
dim $hCombo


;////////////////////////////////////////////////////////////////////////
;       GUI
;////////////////////////////////////////////////////////////////////////
#Region ### START Koda GUI section ### Form=
GUICreate("ComboBox select from list", 396, 296)
;~ $_1 = GUICreate("ComboBox seleziona dalla lista", 247, 718, 393, 133)
$hCombo = GUICtrlCreateCombo("", 2, 60, 396, 296, BitOR($CBS_SIMPLE,$CBS_AUTOHSCROLL,$CBS_DISABLENOSCROLL,$WS_VSCROLL))
$Button_ok = GUICtrlCreateButton("OK", 16, 32, 81, 25, 0)
$Button_cancel = GUICtrlCreateButton("Cancel", 144, 32, 81, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;////////////////////////////////////////////////////////////////////////
;       OPEN text file
;////////////////////////////////////////////////////////////////////////
$file = FileOpen("list.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf



;////////////////////////////////////////////////////////////////////////
;       populate COMBO
;////////////////////////////////////////////////////////////////////////

; Read in lines of text until the EOF is reached
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop    

; Add files
    _GUICtrlComboBox_BeginUpdate($hCombo)
;~; Add string
    _GUICtrlComboBox_AddString($hCombo, $line)
;~; update
    _GUICtrlComboBox_EndUpdate($hCombo)
; select string
    _GUICtrlComboBox_SelectString($hCombo, "This")

Wend

FileClose($file)



;////////////////////////////////////////////////////////////////////////
;       GUI until user action
;////////////////////////////////////////////////////////////////////////
    
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Button_ok
           $SelectedText = GUICtrlRead($hCombo)
           $SelectedItem = _GUICtrlComboBox_GetCurSel($hCombo)
           _GUICtrlComboBox_DeleteString($hCombo,$SelectedItem)
           _GUICtrlComboBox_SetCurSel($hCombo,$SelectedItem)
        Case $Button_cancel
            msgbox(0,"","cancel")
            ExitLoop
            
    EndSwitch
WEnd

GUIDelete()
msgbox(0,"","bye!")


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

Share this post


Link to post
Share on other sites

thank you, next time i use array ! :P

Share this post


Link to post
Share on other sites

Another question about combobox...

Is possible to center values in my column ?

(now values are all on the left)

See help, but speak anly about text and button.

Thank you for help,

m.

Share this post


Link to post
Share on other sites

Don't think you can center text in a combo box.

You can in a list view though. _GUICtrlListView_SetColumn


- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!

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