Jump to content

ComboBox OnSelect?? function


Mau75
 Share

Recommended Posts

Hi,

Can anybody help? I need to create a function that will execute the moment I select an item in a combobox :x

The items in this combobox is dynamic and get populated with another function. Then as soon as a selection is been made from this ComboBox, it needs to call another function and execute.

Alternatively I will need to create some "extra" buttons to do the job... :P

Thanx in advance.

Regards,

:shifty:

Link to comment
Share on other sites

  • Moderators

Mau75,

execute the moment I select an item

Fast enough? :P

#include <GUIConstantsEx.au3>
#include <GUIComboBox.au3>

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

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData($hCombo, "One|Two|Three|Four|Five")

GUISetState()

$sCurrCombo = ""

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    ; If combo is closed and selection has changed
    If GUICtrlRead($hCombo) <> $sCurrCombo And _GUICtrlComboBox_GetDroppedState($hCombo) = False Then
        $sText = GUICtrlRead($hCombo)
        $sCurrCombo = $sText
        _Function($sText)
    EndIf
    ; If combo opened reset flag to allow for selection of same item
    If _GUICtrlComboBox_GetDroppedState($hCombo) Then $sCurrCombo = ""

WEnd

Func _Function($sText)
    MsgBox(0, "Selection", $sText)
EndFunc

If not we can look into intercepting the EN_CHANGE message from the combo's edit control. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hi Melba23,

Thanx for the code, It's working the way I intented it should be. Now only one BIG problem (for me any case). Where and how do I implement it in my code? Here is short peaces explaining my current setup and controls where it shoul be...:

#RequireAdmin
#include <GUIConstantsEx.au3>
#Include <String.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include "diskpart.au3"

Opt("GUIOnEventMode", 1)
$hGUI = GUICreate("WinFE - Diskpart Interface", 500, 500) 
$ListDButton = GUICtrlCreateButton("List Disk", 10, 50, 120, 25)  ;Create the button
$hLabelDisk = GUICtrlCreateLabel("Select Target Disk: ", 10, 90, 135, 40)  ;Create label for disks
$mComboDisk = GUICtrlCreateCombo("", 125, 85,40)  ; create Combo box for Disks selection
GUICtrlSetState($mComboDisk,$GUI_DISABLE)  ;disable the disk combobox until list disk is run
$hEdit = GUICtrlCreateEdit("Feedback from the DISKPART commands being executed", 10, 120, 480, 370, BitOR($ES_MULTILINE,$ES_READONLY))  ;  Create an edit control
GUICtrlSetFont ($hEdit, 8, 400, 0,"Lucida Console")  ;Use of fixed size fonts for alignment purposes
GUICtrlSetOnEvent($ListDButton, "ButtonDFunction")  ; The button's function
GUISetState(@SW_SHOW)  ;Show the GUI.

While 1
    Sleep(10); So we don't use heaps of CPU
WEnd


Func ButtonDFunction()  ;==>List Disk ButtonFunction
    GUICtrlSetData($mComboDisk, "", "")
    GUICtrlSetData($hEdit, "", "")
    _DiskpartStartConsole( $pid, $version, $runError )  ;Call function in diskpart.au3 to start the diskpart.exe console
    GUICtrlSetData($hEdit, "Interacting with Microsoft Diskpart version " & $version & @CRLF & @CRLF)
    _WriteDiskCtrlEdit()
EndFunc   ;==>ButtonFunction End

Func _WriteDiskCtrlEdit()  ;==> Write List Disk info to the Edit box
    $diskCount = _DiskpartListDisks( $pid, $myDisks, $myDisksNum)  ;; Start list disk and create combo box list - diskpart.au3
    $DLIST = ""
    For $n=0 To $myDisksNum
        $DLIST = $DLIST & $myDisks[$n][0] & "|"
    Next
    GUICtrlSetState($mComboDisk,$GUI_ENABLE)
    GUICtrlSetData($mComboDisk, $DLIST, "")
    Local $text = ""
    $read = GUICtrlRead($hEdit)
    $text = $read & StringFormat( "%-8s  %-8s  %-10s  %-10s  Dyn  Gpt", "Disk ###", "Status", "Size", "Free" ) & @CRLF & _
                                "--------  --------  ----------  ----------  ---  ---" & @CRLF ; Join the existing and the new text seperated by a line.
    GUICtrlSetData($hEdit, $text)
    For $m=0 To $myDisksNum
        $read3 = GUICtrlRead($hEdit)
        $text = $read3 & StringFormat( "%-8s  %-8s  %10s  %10s  %-3s  %-3s", _
                                        "Disk " & $myDisks[$m][0], $myDisks[$m][1], $myDisks[$m][2], _
                                        $myDisks[$m][3], $myDisks[$m][4], $myDisks[$m][5]) & @CRLF
        GUICtrlSetData($hEdit, $text)
    Next

    GUICtrlSetState($ListVButton,$GUI_SHOW)
EndFunc  ;==>WriteEditCtrl End

So basically after the _WriteDiskCtrlEdit() it will populate the $mComboDisk = GUICtrlCreateCombo combobox. Then once this is enabled and populated, should your code kick in.

This will call another function in the diskpart.au3 basically selecting the disk that's been selected, and list the volumes on that disk. This in turn will enable and populate another combobox (sameway the first is done) and another selection will be made (with no event).

Once the volume and disks is selected the "Bring online" button will be enabled and executed. One again another function will be called from the diskpart.au3.

Hope this make sense of what I need to do...

So do I need to add your code in the while loop, or can I create something simular to "GUICtrlSetOnEvent($ListDButton, "ButtonDFunction")"?

Thanx for you assistance thus far.

Regards, :x

Edited by Mau75
Link to comment
Share on other sites

  • Moderators

Mau75,

Replace your function with this version which waits until you have selected a value in the combo before returning:

Func ButtonDFunction()  ;==>List Disk ButtonFunction
    GUICtrlSetData($mComboDisk, "", "")
    GUICtrlSetData($hEdit, "", "")
    _DiskpartStartConsole( $pid, $version, $runError )  ;Call function in diskpart.au3 to start the diskpart.exe console
    GUICtrlSetData($hEdit, "Interacting with Microsoft Diskpart version " & $version & @CRLF & @CRLF)
    _WriteDiskCtrlEdit()
    ; Wait until combo is closed and selection has been made
    Do
        Sleep(10)
    Until GUICtrlRead($mComboDisk) <> "" And _GUICtrlComboBox_GetDroppedState($mComboDisk) = False
    ; You get here when a selection has been made in the combo
    ; So now do the next thing you need
EndFunc   ;==>ButtonFunction End

Does that fit in with the rest of your code? :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Does that fit in with the rest of your code? :P

M23

I think so... :x

Thanx, it's working greate.

There is only one other thing that I need. The commands when executed (especially the initial List Disk, take some time to complete, due to the amount of disks installed on the system and whether the disk already went into idle mode.

I need some sort of indication that the program is "busy". Currently it looks like the program just hangs and do nothing. Some sort of popup that will close as soon as the function return from diskpart.au3.

MB

Link to comment
Share on other sites

  • Moderators

Mau75,

Sounds like what the marquee progress was designed for: :x

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

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_On_Exit")
$hProgress = GUICtrlCreateProgress(10, 10, 400, 20, $PBS_MARQUEE)
GUICtrlSendMsg(-1, $PBM_SETMARQUEE, True, 50) ; final parameter is update time in ms

GUICtrlCreateButton("Stop", 10, 400, 80, 30)
GUICtrlSetOnEvent(-1, "_On_Button")

GUISetState()

While 1
    Sleep(10)
WEnd

Func _On_Button()
    GUICtrlSetStyle($hProgress, $GUI_SS_DEFAULT_PROGRESS)
EndFunc

Func _On_Exit()
    Exit
EndFunc

The button shows how best to stop it - unless you want to delete the whole thing of course! :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanx for the info. It looks great and will use it. I will mention you for your assistance...

Now back to sorting out that diskpart.au3 before I can go on... :P

Most of the stuff only work on earlier versions of diskpart and in some cases in Spanish. Then also MS that stick with standards... :x

I need it to work in Win7 & WinPE3

Speak later.

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