david1337

GUI Case when item is selected

6 posts in this topic

Hey guys

I hope that I can get a little help with this one :)

 

In this GUI example using GUIListViewEx, I have a list based on items found in test.txt.

_____________________________________________

item1
item2
item3

____________________________________________

etc....
 

When an item is selected, and I click the GetInfo button, a message will show the text of that item.

Is it possible to activate a case like that as soon as the item is selected, so I don't need a button to start the case?

 

#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>


Global $MainGUI_ManageItemList
Global $File = "test.txt"
Global $FileToArray = FileReadToArray("test.txt")



Call ("MainGUI_ManageItemList")



Func MainGUI_ManageItemList()

    Local $Button1

    $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1)

    $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER)
GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
_GUICtrlListView_SetColumnWidth($cLV, 0, 378)

$Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30)
$RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30)
$GetInfo = GUICtrlCreateButton("GetInfo", 425, 120, 80, 30)


GUISetState(@SW_SHOW, $MainGUI_ManageItemList)



; Intialise ListView
Global $iLV_Index = _GUIListViewEx_Init($cLV)
; Insert lines
_GUIListViewEx_Insert($FileToArray, True)
; Register required messages
_GUIListViewEx_MsgRegister(True, False, False, False)


    While 1
        Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE

                ExitLoop

            Case $Button1
            MsgBox(0,"","Button 1 is pressed")


         Case $RemoveItem
            _GUIListViewEx_Delete()



         Case $GetInfo
         $ItemSelected = _GUICtrlListView_GetSelectedIndices($cLV, True)
         If IsArray($ItemSelected) And $ItemSelected[0] <> 0 Then ;This part makes sure it doesn't crash when no item is selected.
         $ItemSelectedText = _GUICtrlListView_GetItemText($cLV, $ItemSelected[1])


         msgbox (0, "Selected item", $ItemSelectedText)

         EndIf

        EndSwitch
    WEnd
EndFunc   ;==>Main

 

Share this post


Link to post
Share on other sites



david1337,

Perhaps something like this:

#include <GUIConstantsEx.au3>
#include <GUIListViewEx.au3>

Global $iCurrentIndex = 0

Global $MainGUI_ManageItemList
Global $File = @ScriptFullPath
Global $FileToArray = FileReadToArray($File)

MainGUI_ManageItemList()

Func MainGUI_ManageItemList()

    Local $Button1

    $MainGUI_ManageItemList = GUICreate("Manage Item List", 800, 400, -1, -1)

    $cLV = GUICtrlCreateListView("[items]", 10, 10, 400, 775, $LVS_NOCOLUMNHEADER)
    GUICtrlSetFont(-1, 12, 800, 0, "@Arial Unicode MS")
    _GUICtrlListView_SetColumnWidth($cLV, 0, 378)

    $Button1 = GUICtrlCreateButton("Button 1", 425, 10, 80, 30)
    $RemoveItem = GUICtrlCreateButton("Remove Item", 425, 50, 80, 30)

    GUISetState(@SW_SHOW, $MainGUI_ManageItemList)

    ; Intialise ListView
    Global $iLV_Index = _GUIListViewEx_Init($cLV)
    ; Insert lines
    _GUIListViewEx_Insert($FileToArray, True)
    ; Register required messages
    _GUIListViewEx_MsgRegister(True, False, False, False)


    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $Button1
                MsgBox(0, "", "Button 1 is pressed")

            Case $RemoveItem
                _GUIListViewEx_Delete()

        EndSwitch

        $ItemSelected  = _GUICtrlListView_GetSelectedIndices($cLV, True)
        If IsArray($ItemSelected ) And $ItemSelected[0] <> 0 Then
            If $ItemSelected[1] <> $iCurrentIndex Then
                $iCurrentIndex = $ItemSelected[1]
                $ItemSelectedText = _GUICtrlListView_GetItemText($cLV, $ItemSelected[1])
                MsgBox(0, "Selected item", $ItemSelectedText)
            EndIf
        EndIf

    WEnd
EndFunc   ;==>MainGUI_ManageItemList

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

Melba, thank you so much!

As always, a pleasure :)

It worked just as intended, and this time I actually understood what you did!
Now that I know how to do this, I have a lot to work on :D
 

- David

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hey Melba :)

Do you know why in our example here, the first item is selected when the GUI is opened, and it doesn't react to that selection (like when you click an item)?

- David

Edited by david1337

Share this post


Link to post
Share on other sites

david1337,

Quote

Do you know why in our example here, the first item is selected when the GUI is opened

No, but I noticed that it happened and...

Quote

Do you know why in our example here [...] it doesn't react to that selection

...initialised the $iCurrentIndex to 0 to ensure that it did not.

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

#6 ·  Posted (edited)

17 minutes ago, Melba23 said:

Do you know why in our example here [...] it doesn't react to that selection

Ahh yes of course :) Let's pretend I didn't just ask you that.


I will have to work on the automatic highlight of the first item.

 

Thanks!

Edited by david1337

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

    • cookiemonster
      Loading window not closing and not staying on top of main window
      By cookiemonster
      Hi,
      I have a main window with one button, when i press that button it brings up a loading screen, but I have two problems with the loading screen at the moment:
      1) Once I have pressed the button, if i open something else full screen over this autoit project (eg: chrome), then on my task bar click on the autoit project to bring it up to the front, the loading screen does not stay on top of the main window, I tried using $WS_EX_TOPMOST but this makes the loading screen stay on top of all windows, I only want it to stay on top of $Main (my main window GUI)
      2) Once the loading screen has been updated to 100%, it should sleep for a further two seconds then close, but at the moment after that 2 seconds, it goes back down to 25% instead of $LoadingWindow being deleted.
      Has anyone got any thoughts or suggestions?
      #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <FontConstants.au3> $Main = GUICreate("Main Window", 600, 480, -1, -1, -1, $WS_EX_ACCEPTFILES) Global $button_Load = GUICtrlCreateButton("Loading Screen", 484, 98, 89, 20, $WS_GROUP) GUICtrlCreateTab(8, 16, 585, 424) GUICtrlCreateTabItem("Settings") GUICtrlCreateGroup("Settings", 16, 50, 569, 380) GUISetState(@SW_SHOWNORMAL) Func Load() WinSetState($Main, "", @SW_DISABLE) LoadingScreen("Loading @ 25%") GUICtrlSetData($LoadingPercent, 25) sleep(2000) LoadingScreen("Loading @ 100%") GUICtrlSetData($LoadingPercent, 100) sleep(2000) GUIDelete($LoadingWindow) WinSetState($Main, "", @SW_ENABLE) EndFunc Func LoadingScreen($LoadingText) ;Creates a Splash Text Screen with a progress bar. Global $LoadingWindow = GUICreate("", 500, 184, -1, -1, BitOR($WS_POPUP, $WS_BORDER), BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOOLWINDOW)) Global $LoadingPercent = GUICtrlCreateProgress(18, 144, 461, 25, $PBS_SMOOTH) GUICtrlCreateLabel($LoadingText, 2, 44, 494, 88, $SS_CENTER) GUICtrlSetFont(-1, 15, 800, 0, "Calibra", $CLEARTYPE_QUALITY) GUISetState(@SW_SHOW) EndFunc While (1) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button_Load Load() EndSwitch WEnd  
    • Katie_Deely
      Copying selected data from GUI Edit
      By Katie_Deely
      Hey
       
      I have a GUI with an edit-field and a button.
      First I write some text into the edit-field and select a part of it. After that I press the button, and the selection is edited.
      How would I do that, though? When the text is selected and I press the button, it's unselected before the button actually raises an event. 
    • Altor
      GUI problem with While loop and buttons
      By Altor
      Hi all
      My problem is that I have no way to work with buttons in a while loop
      When i run the form i can exit well clicking a close main window and olso if i click in a exit button but if i start the apllication whith a Start button  execute a loop for view a random numbers and then i can't stop the rogram and i can't not exit with a Exit button.
      I think the problem is in the use of events but i can not find the solution....
      Thank's to all
      The exemple is this:
      #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> Opt("GUIOnEventMode", 1) $random_numbers = GUICreate("Random numbers",351,171,-1,-1,-1,-1) GUISetOnEvent($GUI_EVENT_CLOSE, "close") $lavel_number = GUICtrlCreateLabel("",117,36,98,26,BitOr($SS_CENTER,$SS_CENTERIMAGE),$WS_EX_STATICEDGE) GUICtrlSetBkColor(-1,"0xFFFFFF") $start = GUICtrlCreateButton("Start",34,95,100,30,-1,-1) GUICtrlSetOnEvent(-1,"start") $stop = GUICtrlCreateButton("Pause",182,95,100,30,-1,-1) GUICtrlSetOnEvent(-1,"pause") $exit = GUICtrlCreateButton("Exit",112,136,100,30,-1,-1) GUICtrlSetOnEvent(-1,"close") GUISetState(@SW_SHOW) While 1 Sleep (50) Wend Func start() While 1 Sleep(100) Local $a = Random(1,10,1) GUICtrlSetData($lavel_number,$a) WEnd EndFunc Func pause() EndFunc func close() exit EndFunc  
    • Satvik
      Unable to open DLL files
      By Satvik
      Hi 
      I am trying to open a dll using DLLOpen, however everytime i try to do so the function fails and returns -1 result. 
      I have the dll in the same folder as the auto it script. 
      Local $hDLL = DllOpen("C:\Users\310255155\Downloads\COMMGvv2\commg.dll") DllCall($hDLL, "int", "MessageBox", "hwnd", 0, "str", "Some text", "str", "Some title", "int", 0) DllClose($hDLL) MsgBox(0,'result',$hDLL)  
    • S0lidFr0st
      SQL Query Manipulation
      By S0lidFr0st
      Hello! I'm fairly new to using Autoit, I like the language and simplicity, however, there is a bit of a learning curve for me. I'm stuck and need some community help!
      I need to manipulate a query by using GUICtrlCreateDate to select the correct date and pipe the selected date into my actual query in a specific format (yyyymmdd).
      Here is an example:
      _Flag_RecordsetDisplay($sConnectionString, "select * from trips_to_complete_20161122 where trip_type in ('P','C') and trip_status in ('S','PC','DC') and Flagged = 1") Func _Flag_RecordsetDisplay($sConnectionString, $sQUERY) ; Create connection object Local $oConnection = _ADO_Connection_Create() ; Open connection with $sConnectionString _ADO_Connection_OpenConString($oConnection, $sConnectionString) If @error Then Return SetError(@error, @extended, $ADO_RET_FAILURE) ; Executing some query directly to Array of Arrays (instead to $oRecordset) Local $aRecordset = _ADO_Execute($oConnection, $sQUERY, True) ; Clean Up _ADO_Connection_Close($oConnection) $oConnection = Null ; Display Array Content with column names as headers _ADO_Recordset_Display($aRecordset, 'Recordset content') EndFunc ;==>_Flag_RecordsetDisplay The part of the query that needs modified is "trips_to_complete_20161122" I need to be able to select a date (via the gui) and that selection pipe into my query.  
       
      Thanks in Advanced!