Page 1 sur 1

[R] Recuperation listview complet

Posté : jeu. 11 août 2011 11:36
par ricky
Hello,

j'ai un GUICtrlCreateListViewItem et quand je fais un clic droit j'ai récupérer tout le contenu pour l'envoyer dans un tableau, comment faire?

Merci d'avance pour votre aide

Re: [..] Recuperation listview complet

Posté : jeu. 11 août 2011 12:22
par Jerome
Coucou,


Afin de détecter un click droit sur la listview, il faut utiliser ceci :

Code : Tout sélectionner

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; detect click droit
                    ;on place dans un tableau.
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY
 

Je n'ai pas trop le temps de taper la fonction pour ranger dans un tableau, mais il suffit de lire la listview jusqu'a la dernière ligne et de stock chaque ligne / colonne dans un tableau :)



J'avais aussi fait quelque chose pour l'envoyer dans un tableau excel, un peu la même :)

Code : Tout sélectionner

#include <Guilistview.au3>
#include <excel.au3>
GUICreate("listview items", 220, 250, 100, 200)
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUISetState()
Sleep(2000)
$oExcel = _ExcelBookNew()
$iItems = _GUICtrlListView_GetItemCount($listview)
For $iItem = 0 To $iItems-1
    $Zf = _GUICtrlListView_GetItemTextString($listview, $iItem)
    $Zf = StringSplit($Zf, "|", 1)
    _ExcelWriteArray($oExcel, $iItem + 1, 1, $Zf, 0, 1)
Next
 

Jérôme

Re: [..] Recuperation listview complet

Posté : jeu. 11 août 2011 14:58
par ricky
Hello,

merci pour ton aide, J'ai juste un problème pour le mettre dans un tableau, mais je vais chercher un peu.

Problème résolu, je n'avais pas la bonne dimension de tableau. Et voilà ce que ça donne :

Code : Tout sélectionner

$iItems = _GUICtrlListView_GetItemCount($hLv)
    $aValues[0][0] = $iItems - 1
    For $iItem = 0 To $iItems - 1
        $Zf = _GUICtrlListView_GetItemTextString($hLv, $iItem)

        $Zf = StringSplit($Zf, "|", 1)
        _ArrayAdd2D($aValues, $Zf, 0)
    Next