Sign in to follow this  
Followers 0
Clerythecleric

Using a button within combobox

3 posts in this topic

#1 ·  Posted (edited)

Hello,

Working on a project however running into a small issue with accessing a button created after an entry is selected through combobox.
I have created the GUI, a combobox and on selecting different options it will perform random tasks.

On 1 option it will create a label and a button within the GUI however I can't figure out how to now utilize this button

 

While 1
  $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
          Exit
        Case $Combo1
             If GUICtrlRead($Combo1) = "Test1" Then
               GUICtrlCreateLabel("Test Label", 10, 100, 100, 100)
             $testbutton2 = GUICtrlCreateButton("Button", 100, 100, 100, 100)

            ElseIf GUICtrlRead($Combo1) = "Test2" Then
               test2()

            Else
            EndIf
    EndSwitch
 WEnd
 
 
  func test()
    GUICtrlCreateLabel("Test Label", 10, 100, 100, 100)
    $testbutton = GUICtrlCreateButton("Button", 100, 100, 100, 100)
   While 1
  $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
          Exit

    EndSwitch
 WEnd
 EndFunc

  func test2()
    MsgBox("","test2", "test2")
 EndFunc


  func test3()
    MsgBox("","Button", "Button pressed")
 EndFunc



So as the code above showed (I hope lol) when you select Test1 within the combobox it wil create the buton, i need the button to then use test3() after selecting. The only way I have found to do this is to create the button within the function (as shown in Test()) and then have another switch however then you cannot select new options in the combobox as its in a different loop.
I'm sure I'm probably doing it completely wrong somewhere and there is likely a better/more efficient solution.

Any help would be appreciated.
 

Edited by Clerythecleric

Share this post


Link to post
Share on other sites



Yes, use Event Mode instead of GuiGetMsg()

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hello, Thank you. I looked into this method as well as GUICtrlCreateListView which has made my life a whole lot easier than what I was trying to do.
I have now run into an additional problem which is essentially the reverse.

I have a list of options which will perform other functions once you select the field and press 'select' however I would like labels to appear on the GUI when the list item is selected. 

 

$listGUI = GUICreate("AutoIt list item GUI", 500, 300, 100, 200, -1)
  GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Templates")


  $HowDoI = GUICtrlCreateListView("How Do I", 5, 5, 160, 150)
  $IssueWithError = GUICtrlCreateListView("Error Messages", 165, 5, 160, 150)
  $OtherIssues = GUICtrlCreateListView("Other Issues", 325, 5, 160, 150)

  _GUICtrlListView_SetColumnWidth($HowDoI, 0, 130)
  _GUICtrlListView_SetColumnWidth($IssueWithError, 0, 150)
  _GUICtrlListView_SetColumnWidth($OtherIssues, 0, 150)

;;$IssueWithError
  GUICtrlCreateListViewItem("CLSObject Factory", $IssueWithError)
  
  
  
  
  Func SelectItem()
  $sItem = GUICtrlRead(GUICtrlRead($listview))
  $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string

  If $sItem = "SMS" Then
      SMS()
   EndIf

  If $sItem = "Second Item" Then
      MsgBox(0, "Selected Item", $sItem)
   EndIf

EndFunc


To explain what I mean, below is a picture of my GUI. When the options are selected (highlighted in blue) i need a label to appear in the grey gap below to explain what the option will do. How would I go about doing this? I've looked across the forum but there doesn't seem to be anything relevant to this

http://imgur.com/nPhgHw6

Many thanks for your time and patience.

MyGUI.png

Edited by Clerythecleric

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