Jump to content
daniel95

Double Click on ListItem and then to InputBox

Recommended Posts

daniel95

Hi Everyone,

i'm new at this board so at first hello :)

i want to create a function, that will fill with a double click on a listview item inputboxes of my gui.

This is my GUI:
 

$gui2 = GUICreate("Benutzersteuerung", 612, 460, 189, 132)
$gui2_inp_firstname = GUICtrlCreateInput("", 90, 4, 146, 21)
$gui2_inp_lastname = GUICtrlCreateInput("", 90, 28, 146, 21)
$gui2_inp_badgenumber = GUICtrlCreateInput("", 90, 52, 146, 21)
$gui2_btn_add = GUICtrlCreateButton("ADD", 266, 8, 60, 25)
$gui2_btn_del = GUICtrlCreateButton("DEL", 330, 8, 60, 25)
$gui2_btn_mod = GUICtrlCreateButton("MOD", 266, 40, 60, 25)
$gui2_btn_search = GUICtrlCreateButton("SEARCH", 330, 40, 60, 25)
$gui2_lsv_users = GUICtrlCreateListView("Badgenummer|Vorname|Nachname", 0, 75, 609, 383)
$gui2_label1 = GUICtrlCreateLabel("Vorname", 12, 8, 70, 17)
$gui2_label2 = GUICtrlCreateLabel("Nachname", 12, 32, 70, 17)
$gui2_label3 = GUICtrlCreateLabel("Badgenummer", 12, 56, 70, 17)
    _GUICtrlListView_SetColumnWidth($gui2_lsv_users, 0, 150)
GUISetState(@SW_HIDE, $gui2)

I already searched everything, but i'm not able to make this happen :(

 

Thanks in advance.

 

-Daniel

Share this post


Link to post
Share on other sites
daniel95

Okay, i had changed my gui to this:
 

Global $gui2_lsv_users = GUICtrlCreateListView("", 0, 75, 609, 383)
     _GUICtrlListView_InsertColumn($gui2_lsv_users, 0, "Badgenummer", 100)
     _GUICtrlListView_InsertColumn($gui2_lsv_users, 1, "Vorname", 150)
     _GUICtrlListView_InsertColumn($gui2_lsv_users, 2, "Nachname", 150)

Func readDataForGui2()
    $sql2 = _EzMySql_GetTable2d("SELECT mitarbeiter.ID, mitarbeiter.vorname, mitarbeiter.nachname FROM mitarbeiter;")
    _ArrayDelete($sql2, 0)
    _GUICtrlListView_AddArray($gui2_lsv_users, $sql2)
EndFunc

But i want to display my selected item i get "1" as value:
 

Case $gui2_btn_del
            ;delUser()
            Local $sSelItems = ControlListView($gui2, '', $gui2_lsv_users, 'GetSelected', 1)
            MsgBox(0, "Info", "Info: " & $sSelItems)

 

Can someone please explain me why this not worked

Share this post


Link to post
Share on other sites
Subz

In future it would be better to post executable code as you probably would get more help.

With that being said I assume you were after something like below?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>

Local $iSelection = "", $aSelection = ""

Local $hGui = GUICreate("Benutzersteuerung", 612, 460, 189, 132)
GUICtrlCreateLabel("Vorname", 12, 8, 70, 17)
    Local $idFirstName = GUICtrlCreateInput("", 90, 4, 146, 21)
GUICtrlCreateLabel("Nachname", 12, 32, 70, 17)
    Local $idLastName = GUICtrlCreateInput("", 90, 28, 146, 21)
GUICtrlCreateLabel("Badgenummer", 12, 56, 70, 17)
    Local $idBadgeNumber = GUICtrlCreateInput("", 90, 52, 146, 21)
Local $idAddButton = GUICtrlCreateButton("ADD", 266, 8, 60, 25)
Local $idDelButton = GUICtrlCreateButton("DEL", 330, 8, 60, 25)
Local $idModButton = GUICtrlCreateButton("MOD", 266, 40, 60, 25)
Local $idSearchButton = GUICtrlCreateButton("SEARCH", 330, 40, 60, 25)
Local $idListView = GUICtrlCreateListView("Badgenummer|Vorname|Nachname", 0, 75, 609, 383, BitOR($LVS_EDITLABELS, $LVS_SINGLESEL))
    _GUICtrlListView_SetColumnWidth($idListView, 0, 150)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idAddButton
            $sGuiInputData = ""
            $sGuiInputData &= GUICtrlRead($idFirstName) & "|"
            $sGuiInputData &= GUICtrlRead($idLastName) & "|"
            $sGuiInputData &= GUICtrlRead($idBadgeNumber)
            GUICtrlCreateListViewItem($sGuiInputData, $idListView)
            GUICtrlSetData($idFirstName, "")
            GUICtrlSetData($idLastName, "")
            GUICtrlSetData($idBadgeNumber, "")
        Case $idDelButton
            _GUICtrlListView_DeleteItemsSelected($idListView)
        Case $idModButton
            Switch GUICtrlRead($idModButton)
                Case "Mod"
                    $iSelection = _GUICtrlListView_GetSelectionMark($idListView)
                        If $iSelection = -1 Then ContinueLoop
                    $aSelection = _GUICtrlListView_GetItemTextArray($idListView, $iSelection)
                        If $aSelection[0] = 0 Then ContinueLoop
                    GUICtrlSetState($idAddButton, $GUI_DISABLE)
                    GUICtrlSetState($idDelButton, $GUI_DISABLE)
                    GUICtrlSetState($idSearchButton, $GUI_DISABLE)
                    GUICtrlSetData($idModButton, "Update")
                    GUICtrlSetData($idFirstName, $aSelection[1])
                    GUICtrlSetData($idLastName, $aSelection[2])
                    GUICtrlSetData($idBadgeNumber, $aSelection[3])
                Case "Update"
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idFirstName), 0)
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idLastName), 1)
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idBadgeNumber), 2)
                    GUICtrlSetData($idModButton, "Mod")
                    GUICtrlSetState($idAddButton, $GUI_ENABLE)
                    GUICtrlSetState($idDelButton, $GUI_ENABLE)
                    GUICtrlSetState($idSearchButton, $GUI_ENABLE)
                    $iSelection = ""
                    $aSelection = ""
            EndSwitch
    EndSwitch
WEnd

 

  • Thanks 1

Share this post


Link to post
Share on other sites
daniel95
21 hours ago, Subz said:

In future it would be better to post executable code as you probably would get more help.

With that being said I assume you were after something like below?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>

Local $iSelection = "", $aSelection = ""

Local $hGui = GUICreate("Benutzersteuerung", 612, 460, 189, 132)
GUICtrlCreateLabel("Vorname", 12, 8, 70, 17)
    Local $idFirstName = GUICtrlCreateInput("", 90, 4, 146, 21)
GUICtrlCreateLabel("Nachname", 12, 32, 70, 17)
    Local $idLastName = GUICtrlCreateInput("", 90, 28, 146, 21)
GUICtrlCreateLabel("Badgenummer", 12, 56, 70, 17)
    Local $idBadgeNumber = GUICtrlCreateInput("", 90, 52, 146, 21)
Local $idAddButton = GUICtrlCreateButton("ADD", 266, 8, 60, 25)
Local $idDelButton = GUICtrlCreateButton("DEL", 330, 8, 60, 25)
Local $idModButton = GUICtrlCreateButton("MOD", 266, 40, 60, 25)
Local $idSearchButton = GUICtrlCreateButton("SEARCH", 330, 40, 60, 25)
Local $idListView = GUICtrlCreateListView("Badgenummer|Vorname|Nachname", 0, 75, 609, 383, BitOR($LVS_EDITLABELS, $LVS_SINGLESEL))
    _GUICtrlListView_SetColumnWidth($idListView, 0, 150)

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idAddButton
            $sGuiInputData = ""
            $sGuiInputData &= GUICtrlRead($idFirstName) & "|"
            $sGuiInputData &= GUICtrlRead($idLastName) & "|"
            $sGuiInputData &= GUICtrlRead($idBadgeNumber)
            GUICtrlCreateListViewItem($sGuiInputData, $idListView)
            GUICtrlSetData($idFirstName, "")
            GUICtrlSetData($idLastName, "")
            GUICtrlSetData($idBadgeNumber, "")
        Case $idDelButton
            _GUICtrlListView_DeleteItemsSelected($idListView)
        Case $idModButton
            Switch GUICtrlRead($idModButton)
                Case "Mod"
                    $iSelection = _GUICtrlListView_GetSelectionMark($idListView)
                        If $iSelection = -1 Then ContinueLoop
                    $aSelection = _GUICtrlListView_GetItemTextArray($idListView, $iSelection)
                        If $aSelection[0] = 0 Then ContinueLoop
                    GUICtrlSetState($idAddButton, $GUI_DISABLE)
                    GUICtrlSetState($idDelButton, $GUI_DISABLE)
                    GUICtrlSetState($idSearchButton, $GUI_DISABLE)
                    GUICtrlSetData($idModButton, "Update")
                    GUICtrlSetData($idFirstName, $aSelection[1])
                    GUICtrlSetData($idLastName, $aSelection[2])
                    GUICtrlSetData($idBadgeNumber, $aSelection[3])
                Case "Update"
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idFirstName), 0)
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idLastName), 1)
                    _GUICtrlListView_SetItemText($idListView, $iSelection, GUICtrlRead($idBadgeNumber), 2)
                    GUICtrlSetData($idModButton, "Mod")
                    GUICtrlSetState($idAddButton, $GUI_ENABLE)
                    GUICtrlSetState($idDelButton, $GUI_ENABLE)
                    GUICtrlSetState($idSearchButton, $GUI_ENABLE)
                    $iSelection = ""
                    $aSelection = ""
            EndSwitch
    EndSwitch
WEnd

 

Thank you SOOOOO much! It worked fine for me!!

_GUICtrlListView_SelectionMark & _GUICtrlListView_GetItemTextArray is what i was looking for.

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

×