Jump to content

GUI Case when item is selected


david1337
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

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

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

  • Moderators

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

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

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

×
×
  • Create New...