Page 1 sur 1

[..] Listview edit item ?

Posté : mar. 28 janv. 2014 16:29
par TiOm4cK
Bonjour a tous :wink:
dans le cadre d'une rencontre de plusieurs ecole pour un cross je suis en train de faire un petit script qui va nous gerer tous ca simplement

mais j'ai besoin pour cela de vos talent :)
en effet j'ai un petit souci dans ce petit exemple vraiment minime j'aimerai pouvoir modifier la nombre d'enfant participant via " $menumodif " qui nous renvoie vers une input box nous demandant le nouveau nombres de participants

Code : Tout sélectionner

#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 468, 275, 192, 124)
$List1 = GUICtrlCreateListView("ecole|section|classe|nb eleve|nb eleve participant", 16, 32, 400, 227)
$newitem = "ST paul|ce1|jaune|37|25"
GUICtrlCreateListViewItem($newitem, $List1)
$menu1 = GUICtrlCreateContextMenu($List1)
$menumodif = GUICtrlCreateMenuItem("Modifier nb enfant participant", $menu1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $menumodif
            $newvaleur = InputBox("nouvelle valeur", "indiquez le nombre d'enfant participant")

    EndSwitch
WEnd
 
mais j'ai un soucis je n'arrive pas a utilise la fonction _GUICtrlListView_EditLabel ( $hWnd, $iIndex )
car elle n'utilise que deux argument et ca edit que les items de la premiere colonne hors dans mon cas j'aimerai que ce soit la colonne numero 4 qui soit actualisée.

merci par avance pour votre aide :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 17:19
par xPunKx
Bonjour, j'ai créé ceci, il y a un bout de temps. En gros, tu double clique sur l'item à modifier et tu entres la donnée et tu pèses sur ENTER pour la valider. J'espère que cela pourra t'aider :)

Code : Tout sélectionner

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Global $aLV_Click_Info, $hTmp_Edit, $fDblClk = False

$GUI = GUICreate("Selecting", 515, 100)
$NVT = _GUICtrlListView_Create($GUI, "", 1, 1, 513, 98, $LVS_REPORT, $WS_EX_CLIENTEDGE)
_GUICtrlListView_SetExtendedListViewStyle($NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
_GUICtrlListView_InsertColumn($NVT, 0, "Col 1", 170, 2)
_GUICtrlListView_InsertColumn($NVT, 1, "Col 2", 170, 2)
_GUICtrlListView_InsertColumn($NVT, 2, "Col 3", 157, 2)
_GUICtrlListView_AddItem($NVT, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($NVT, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($NVT, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($NVT, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($NVT, 1, "Row 2: Col 2", 1, 2)
_GUICtrlListView_AddItem($NVT, "Row 3: Col 1", 2)

ControlListView("Selecting", "", "SysListView321", "SelectClear")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    If $hTmp_Edit <> 0 Then ; If a temporary edit exists
        If _IsPressed("0D") Then ; If ENTER pressed
            $sText = GUICtrlRead($hTmp_Edit) ; Set label to edit content
            _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            GUICtrlDelete($hTmp_Edit) ; Delete temporary edit
            $hTmp_Edit = 0
        EndIf
    EndIf

    If $fDblClk Then ; If an item was double clicked
        $fDblClk = False
        GUICtrlDelete($hTmp_Edit) ; Delete any existing temporary edits
        $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Read current text of clicked label

        Switch $aLV_Click_Info[1] ; Get label position
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1])
            EndSwitch

        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 8, $aLV_Rect_Info[1] + 7, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $NVT
            Switch $iCode
                Case $NM_DBLCLK
                    $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT)
                    If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 17:28
par TiOm4cK
mo script etant deja bien entammé j'aimerai pouvoir garder mon simple GUICtrlCreateListView et malheuresement avec un simple GUICtrlCreateListView

le code ci dessus ne fonctionne pas merci tout de meme pour ta reponse rapide :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 17:41
par xPunKx
De quoi il ne fonctionne pas ? Tu double clique sur un item pis tu changes ce que tu veux en ensuite ENTER et la cellule est changé. Se script marche très bien depuis plusieurs mois et chez d'autre utilisateur de notre réseau. Bref, quel version tu as ?

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 17:57
par TiOm4cK
ton script marche tres bien il n'y a pas de soucis c'est juste que pour creer ton tableau il utilise la fonction _GUICtrlListView_Create()

hors dans mon cas mon j'utilise la fonction GUICtrlCreateListView()

mais j'aimerai ne pas a avoir a changer cette fonction car ca risquerai de me poser probleme a plusieurs endroit dans mon script

quand j'ai dit que ca ne fonctionnait pas c'est parce que j'ai changer ton bout de code avec la fonction GUICtrlCreateListView() mais ca ne fonctionne pas

si tu as un moyen de convertir ce code pour qu'il focntionne avec cette fonction (GUICtrlCreateListView()) ce serait vraiment cool :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 18:11
par xPunKx
Je peux toujours essayer, mais je doute que cela sois possible.. Poste ton code et je vais voir ce que je peux faire :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 18:16
par TiOm4cK
trop de ligne tu va t'embetter pour rien surtout avec ma super organisation :P

non bah tampis si ce n'est pas possible je vais essayer de faire sans mais ca m'embette un peu ;)

je vais attendre d'autre commentaire sinon bein tampis merci baucoup de ton aide totu de meme :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 19:01
par xPunKx
Voilà ! J'ai réussi avec beaucoup d'effort :) J'espère que cela va combler se que tu voulais :D

Code : Tout sélectionner

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Global $aLV_Click_Info, $hTmp_Edit, $fDblClk = False

$GUI = GUICreate("Selecting", 515, 100)
$1NVT = GUICtrlCreateListView( "", 1, 1, 513, 98, $LVS_REPORT, $WS_EX_CLIENTEDGE)
$NVT = GuiCtrlGetHandle($1NVT)
_GUICtrlListView_SetExtendedListViewStyle($1NVT, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
GUICtrlCreateListViewItem("aaa|bbb", $1NVT)
GUICtrlCreateListViewItem("bbb|ccc", $1NVT)
GUICtrlCreateListViewItem("ccc|ddd", $1NVT)

ControlListView("Selecting", "", "SysListView321", "SelectClear")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1

    If $hTmp_Edit <> 0 Then ; If a temporary edit exists
        If _IsPressed("0D") Then ; If ENTER pressed
            $sText = GUICtrlRead($hTmp_Edit) ; Set label to edit content
            _GUICtrlListView_SetItemText($NVT, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            GUICtrlDelete($hTmp_Edit) ; Delete temporary edit
            $hTmp_Edit = 0
        EndIf
    EndIf

    If $fDblClk Then ; If an item was double clicked
        $fDblClk = False
        GUICtrlDelete($hTmp_Edit) ; Delete any existing temporary edits
        $sTmp_Text = _GUICtrlListView_GetItemText($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Read current text of clicked label

        Switch $aLV_Click_Info[1] ; Get label position
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($NVT, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($NVT, $aLV_Click_Info[0], $aLV_Click_Info[1])
            EndSwitch

        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 2, $aLV_Rect_Info[1] + 3, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)
    EndIf

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $NVT
            Switch $iCode
                Case $NM_DBLCLK
                    $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($NVT)
                    If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edit : Suppression totale de _GUICtrlListView* pour les données sauf pour le style.

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 19:07
par mikell
Pour que le script fonctionne avec GUICtrlCreateListView il suffit de modifier ça à la création de la listview :

Code : Tout sélectionner

; remplacer
;$NVT = _GUICtrlListView_Create($GUI, "", 1, 1, 513, 98, $LVS_REPORT, $WS_EX_CLIENTEDGE)
; par
$idNVT = GUICtrlCreateListView( "", 1, 1, 513, 98, $LVS_REPORT, $WS_EX_CLIENTEDGE)
$NVT = GuiCtrlGetHandle($idNVT)
Edit
Rapide xPunKx :mrgreen:

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 21:39
par TiOm4cK
merci pour ces reponse mais je ne comprend pas pourquoi cela ne fonctionne pas avec mon code d'originie j'ai tenter de modifier mais je crois que ca ne focntionne pas voir code ci dessous

Code : Tout sélectionner

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Global $aLV_Click_Info, $hTmp_Edit, $fDblClk = False

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 468, 275, 192, 124)

$idNVT = GUICtrlCreateListView( "", 1, 1, 513, 98, $LVS_REPORT, $WS_EX_CLIENTEDGE)
$List1 = GuiCtrlGetHandle($idNVT)
_GUICtrlListView_SetExtendedListViewStyle($List1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT))
;$List1 = GUICtrlCreateListView("ecole|section|classe|nb eleve|nb eleve participant", 16, 32, 400, 227)
$newitem = "ST paul|ce1|jaune|37|25"
GUICtrlCreateListViewItem($newitem, $List1)

GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
#EndRegion ### END Koda GUI section ###

While 1

     If $hTmp_Edit <> 0 Then ; If a temporary edit exists
        If _IsPressed("0D") Then ; If ENTER pressed
            $sText = GUICtrlRead($hTmp_Edit) ; Set label to edit content
            _GUICtrlListView_SetItemText($List1, $aLV_Click_Info[0], $sText, $aLV_Click_Info[1])
            GUICtrlDelete($hTmp_Edit) ; Delete temporary edit
            $hTmp_Edit = 0
        EndIf
    EndIf

    If $fDblClk Then ; If an item was double clicked
        $fDblClk = False
        GUICtrlDelete($hTmp_Edit) ; Delete any existing temporary edits
        $sTmp_Text = _GUICtrlListView_GetItemText($List1, $aLV_Click_Info[0], $aLV_Click_Info[1]) ; Read current text of clicked label

        Switch $aLV_Click_Info[1] ; Get label position
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($List1, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($List1, $aLV_Click_Info[0], $aLV_Click_Info[1])
            EndSwitch

        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 8, $aLV_Rect_Info[1] + 7, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)
    EndIf

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $List1
            Switch $iCode
                Case $NM_DBLCLK
                    $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($List1)
                    If $aLV_Click_Info[0] <> -1 Then $fDblClk = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
une idee. sinon c'est super pour les reponse vraiment deja je vois que c'est possible :)
merci beaucoup

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 22:16
par xPunKx
Il faut tu mettre des colonnes à ta Listview et tu essayais d'ajouter des items à $List1 qui retourne le handle du control
► Afficher le texte
Voilà, ça fonctionne mieux comme ça :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 23:18
par TiOm4cK
JE SUIS TROP BETES c'est sur que sans colones ca fonctionne moins bien ;)

je vous suis tres reconaissant pour le travaille fourni vraiment merci xPunKx et mikell :D

j'ai un dernier service a vous demande si je veux que seuleument les items du tableau "nb eleve" soit editable comment faire ?

encore merci pour le travail deja fourni :)

Re: [..] Listview edit item ?

Posté : mar. 28 janv. 2014 23:49
par xPunKx
Ce que j'ai trouvé (peut-être pas la meilleur solution, mais qui fonctionne) :

Code : Tout sélectionner

        Switch $aLV_Click_Info[1] ; Get label position
            Case 0 ; On Item
                $aLV_Rect_Info = _GUICtrlListView_GetItemRect($List1, $aLV_Click_Info[0], 2)
            Case Else ; On SubItem
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($List1, $aLV_Click_Info[0], $aLV_Click_Info[1])
            EndSwitch

        $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 4, $aLV_Rect_Info[1] + 3, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit
        GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)
        EndSwitch

par

        Switch $aLV_Click_Info[1] ; Get label position
            Case 3 ; = column "Nb élève"
                $aLV_Rect_Info = _GUICtrlListView_GetSubItemRect($List1, $aLV_Click_Info[0], $aLV_Click_Info[1])
                $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aLV_Rect_Info[0] + 4, $aLV_Rect_Info[1] + 3, $aLV_Rect_Info[2] - $aLV_Rect_Info[0], $aLV_Rect_Info[3] - $aLV_Rect_Info[1], 0) ; Create temporary edit
                GUICtrlSetState($hTmp_Edit, $GUI_FOCUS)
        EndSwitch
 

Re: [..] Listview edit item ?

Posté : mer. 29 janv. 2014 02:11
par TiOm4cK
C'est super moi ca me va parfaitement merci encore une fois pour ton aide :D . j'apprecie beaucoup cette communaute qui est toujours tres reactive sur ce bonne nuit :P

Re: [..] Listview edit item ?

Posté : mer. 29 janv. 2014 08:57
par jguinch
Uniquement pour la colonne 3, tu peux aussi faire comme ça :
► Afficher le texte

Re: [..] Listview edit item ?

Posté : mer. 29 janv. 2014 15:50
par TommyDDR
Si votre message est résolu, pensez à remplacer [..] par [R] dans votre 1er message ;)