Page 1 sur 1
[..] sélections multiples avec listview ?
Posté : lun. 28 févr. 2011 23:06
par vince59
Bonjour,
J'ai utilisé pour la première fois le listview. Or, je n'arrive pas à faire des sélections multiples.
L'idée sous-jacente est de faire une IHM permettant de sélectionner plusieurs machines et d'installer un logiciel sur ces machines. Et donc de faire une liste (listview) avec les noms et les adresses IP des machines à installer.
Pour ceci, soit je crée plusieurs checkbox, soit une listview. Mais je trouve la listview plus élégante. Mais je n'arrive pas à faire des sélections multiples.
J'ai cherché sur le forum mais je suis resté bredouille. Si quelqu'un a une idée...

Merci d'avance.
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $listview, $button, $item1, $item2, $item3, $item4, $item5, $item6, $input1, $msg
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; will change background color
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
GUICtrlSetState(-1, $GUI_FOCUS)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
GUICtrlSetState(-1, $GUI_FOCUS)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
GUICtrlSetState(-1, $GUI_FOCUS)
$item4 = GUICtrlCreateListViewItem("item4|col41|col42", $listview)
GUICtrlSetState(-1, $GUI_FOCUS)
$item5 = GUICtrlCreateListViewItem("item5|col51|col52", $listview)
GUICtrlSetState(-1, $GUI_FOCUS)
$item6 = GUICtrlCreateListViewItem("item6|col61|col62", $listview)
;GUICtrlSetState(-1, $GUI_FOCUS)
$input1 = GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
GUISetState()
Do
$msg = GUIGetMsg()
Select
Case $msg = $button
MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
Case $msg = $listview
MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Re: [..] sélections multiples avec listview ?
Posté : mar. 01 mars 2011 00:19
par leoueb
Salut, j'ai cherché de mon côté pour un besoin similaire et j'ai trouvé la fonction : _GUICtrlListBox_Create
pour cela tu dois utiliser l'udf : <GuiListBox.au3>
Pour rendre ta liste box multi sélection, tu as deux possibilitées de paramétrage de "iStyles" :
$LBS_MULTIPLESEL => a chaque clic sur une ligne ça sélectionne ou déselectionne.
$LBS_EXTENDEDSEL => Ce mode la nécessite l'utilisation de la touche "CTRL"
Re: [..] sélections multiples avec listview ?
Posté : sam. 26 mars 2011 08:51
par Strofe
Bonjour
Je relance le sujet.
► Afficher le texte
Code : Tout sélectionner
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include 'LV_Format_include.au3'
HotKeySet("^a", "SelectAll" ) ;^ Ctrl, + Shift, ! Alt
Local $col = ''
$col &= 'Code Article' & '|'
$col &= 'Code Famille' & '|'
$col &= 'Mot Directeur' & '|'
$col &= 'Designation1' & '|'
$col &= 'Designation3' & '|'
$col &= 'Localisation' & '|'
$GUI = GUICreate('', 500, 500,100,100 )
;~ $LVS_EX_FULLROWSELECT = Selection de la ligne complète
;~ $LVS_EX_GRIDLINES = Cadrillage
$lv = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 300, 150, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
$hLV = GUICtrlGetHandle($lv)
For $i = 0 To 5
_GUICtrlListView_SetColumnWidth($hLV, $i, 49)
Next
Local $aHWnd = $hLV
_GUICtrlListView_Formatting_Startup($GUI, $aHWnd)
; add new Items
_GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5')
_GUICtrlListView_AddOrIns_Item($hLV, 'Blub0|Blub1|Blub2|Blub3|Blub4|Blub5')
_GUICtrlListView_AddOrIns_Item($hLV, 'Club0|Club1|Club2|Club3|Club4|Club5')
_GUICtrlListView_AddOrIns_Item($hLV, 'Blab0|Blab1|Blab2|Blab3|Blab4|Blab5')
_GUICtrlListView_AddOrIns_Item($hLV, 'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5')
GUISetState(@SW_SHOW, $GUI)
WinSetTitle($GUI, '', 'Now click column header to sort')
Do
Until GUIGetMsg() = -3
; clear ressources
_GUICtrlListView_Formatting_Shutdown()
Func SelectAll()
_GUICtrlListView_SetItemSelected ($hLV,-1)
EndFunc
Pour ma part je souhaite désactiver le drag and drop
A+
Re: [..] sélections multiples avec listview ?
Posté : dim. 27 mars 2011 20:50
par Strofe
Bonsoir
Pour répondre à ta question...
1 ligne à ajouter
1 ligne à modifier
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;~ A ajouter
#include <GuiListView.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $listview, $button, $item1, $item2, $item3, $item4, $item5, $item6, $input1, $msg
GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0x00E0FFFF) ; will change background color
;~ A modifier
$listview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 150, BitRotate($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES))
$button = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
$item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
$item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
$item4 = GUICtrlCreateListViewItem("item4|col41|col42", $listview)
$item5 = GUICtrlCreateListViewItem("item5|col51|col52", $listview)
$item6 = GUICtrlCreateListViewItem("item6|col61|col62", $listview)
$input1 = GUICtrlCreateInput("", 20, 200, 150)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
GUISetState()
Do
$msg = GUIGetMsg()
Select
Case $msg = $button
MsgBox(0, "listview item", GUICtrlRead(GUICtrlRead($listview)), 2)
Case $msg = $listview
MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Re: [..] sélections multiples avec listview ?
Posté : mar. 15 nov. 2011 18:16
par theAvenger
Pour avoir plusieurs sélections, il suffit de faire ceci :
En revanche, je ne parviens pas à obtenir toutes les sélections, je ne reçois que la première.
Une idée ?
Re: [..] sélections multiples avec listview ?
Posté : mer. 16 nov. 2011 04:31
par GaRydelaMer
Bonsoir
Pour la listview moi je la créer comme ca:
Code : Tout sélectionner
$hListView = _GUICtrlListView_Create($GUI, "Col1 |Col 2 |Col 3 ", 20, 145, 630, 365, _
BitOR($LVS_REPORT, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS))
_GUICtrlListView_SetExtendedListViewStyle($hListView , _
BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, [color=#BF0000]$LVS_EX_CHECKBOXES[/color], $LVS_EX_DOUBLEBUFFER, $WS_EX_CLIENTEDGE))
Voila une fonction qui renvoie la liste des items coché dans une listview, un tableau ou une chaine séparateur de votre choix
► Afficher le texte
Code : Tout sélectionner
; #FUNCTION# ====================================================================================================================
; Name...........: My_GUICtrlListView_GetCheckedIndices
; Description ...: Retrieve indices of Checked item(s)
; Syntax.........: My_GUICtrlListView_GetCheckedIndices($hWnd, $fArray = False, $Sep = "|")
; Parameters ....: $hWnd - Handle to the control
; $fArray - Return string or Array
; |True - Returns array
; |False - Returns delimited string, see next parameter. Default: False
; $Sep - Symbol for delimited string. Default: "|" pipe
; Return values .: Success - Selected indices Based on $fArray:
; +Array - With the following format
; |[0] - Number of Items in array (n)
; |[1] - First item index
; |[2] - Second item index
; |[n] - Last item index
; |String - With the following format
; |"0|1|2|n"
; Failure - Based on $fArray
; |Array - With the following format
; |[0] - Number of Items in array (0)
; |String - Empty ("")
; Author ........: Gary delaMer
; Modified.......:
; Remarks .......:
; Related .......: _GUICtrlListView_GetSelectedIndices
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func My_GUICtrlListView_GetCheckedIndices($hWnd, $bArray = False, $Sep = "|")
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName)
Local $i = 0, $iCount = _GUICtrlListView_GetItemCount($hWnd)
Local $sIndices, $aIndices[$iCount + 1] = [0]
For $iItem = 0 To $iCount - 1
If _GUICtrlListView_GetItemChecked($hWnd, $iItem) Then
If Not $bArray Then
If StringLen($sIndices) Then
$sIndices &= $Sep & $iItem
Else
$sIndices = $iItem
EndIf
Else
$i += 1
$aIndices[$i] = $iItem
EndIf
EndIf
Next
If Not $bArray Then
Return String($sIndices)
Else
$aIndices[0] = $i
ReDim $aIndices[$i + 1]
Return $aIndices
EndIf
EndFunc ;==>My_GUICtrlListView_GetCheckedIndices
Re: [..] sélections multiples avec listview ?
Posté : mer. 16 nov. 2011 16:19
par theAvenger
Merci, mais ce n'est pas exactement ce que j'attendais.
Re: [..] sélections multiples avec listview ?
Posté : mer. 16 nov. 2011 19:48
par mikell
Peut-être une boucle For sur les index des items avec
Code : Tout sélectionner
ControlListView ( "title", "text", $listview, "GetText", Item, SubItem )

Re: [..] sélections multiples avec listview ?
Posté : jeu. 17 nov. 2011 00:07
par theAvenger
En effet mais je ferais plutôt un
Code : Tout sélectionner
$data_liste = ControlListView($GUI, "", $liste, "GetSelected", 1)
Puis avec une boucle, on peut séparer les items renvoyés et obtenir leur valeur (le texte).
Ca résoud mon problème, merci !!!