Code : Tout sélectionner
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
$hGUI = GUICreate("ListView SimpleSort", 310, 250)
$BtInfo = GUICtrlCreateButton("Info", 192, 16, 81, 33, $WS_GROUP)
$hListView = GUICtrlCreateListView("col1|col2|col3", 10, 10, 154, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
GUICtrlCreateListViewItem("line8|a|tyr", $hListView)
GUICtrlCreateListViewItem("line7|b|xdf", $hListView)
GUICtrlCreateListViewItem("line6|c|mlk", $hListView)
GUICtrlCreateListViewItem("line5|d|aze", $hListView)
GUICtrlCreateListViewItem("line4|e|pot", $hListView)
GUICtrlCreateListViewItem("line3|f|vgh", $hListView)
GUICtrlCreateListViewItem("line2|g|oij", $hListView)
GUICtrlCreateListViewItem("line1|h|ghj", $hListView)
; permet de dimentionner la largeur des colones
_GUICtrlListView_SetColumnWidth($hListView, 0, 40)
_GUICtrlListView_SetColumnWidth($hListView, 1, 40)
_GUICtrlListView_SetColumnWidth($hListView, 2, 40)
; permet d'afficher la grille sur une liste view
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUISetState(@SW_SHOW)
; ces 2 lignes sont tres importente pour trier une liste view
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)]
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $BtInfo
;permet de recuperer le contenu d'une case selectionné
$Col1 = _GetDataColumn($hListView,1) ; la on recupere les valeur de la colonne 1
$Col2 = _GetDataColumn($hListView,2)
$Col3 = _GetDataColumn($hListView,3)
MsgBox(0,"test","Col1: "&$Col1&@CRLF&"Col2: "&$Col2&@CRLF&"Col3: "&$Col3 )
EndSwitch
WEnd
Func _GetDataColumn($MyListView,$ColumnItem = 1,$ItemAttributes = 3)
; dans cette fonction le 3eme parametre est initialiser a 3 par defaut
; 3 c'est la valeur pour recuperer du texte....
Local $Indice, $Item
$Indice = _GUICtrlListView_GetSelectedIndices($MyListView) ; récupere l'indice de la ligne sélectionné
$Item = _GUICtrlListView_GetItem($MyListView,int($Indice),$ColumnItem -1 )
Return $Item[$ItemAttributes]
EndFunc
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 $LVN_COLUMNCLICK ; A column was clicked
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc