ne pouvoir selectionner qu'une seule checkbox

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

ne pouvoir selectionner qu'une seule checkbox

#1

Message par yohanb767 »

Bonjour , voici un script qui me permet dans mon tableau de selectionner une ou plusieur checkbox
j'aimerai n'avoir la possibilité d'en selectionner qu'une seule et que les autres soit grisés

le problème c'est que je n'arrive pas l'inclure dans mon script

le voici


#region Includes
#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GuiEdit.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#endregion

#region Variable Global hors Interface
Global $hListView

#endregion

#region Interface Menu
; ####################################### Début de la création de l'interface Menu ########################################################
Global $F_Menu = GUICreate("Gestion des Litiges - v1.0.0", 565, 213, 192, 124)
Global $Lbl_Titre = GUICtrlCreateLabel("GESTION DES LITIGES", 112, 16, 400, 41)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Global $Btn_NewPret = GUICtrlCreateButton("NOUVEAU LITIGE", 32, 72, 209, 89)
Global $Btn_ModifPret = GUICtrlCreateButton("VOIR / MODIFIER / SUPPRIMER UN LITIGE", 328, 72, 209, 89, $BS_MULTILINE)
; ############################################### Fin de la création ######################################################################
#endregion

#region Interface Formulaire
; ################################# Début de la création de l'interface Formulaire ########################################################
Global $F_Formulaire = GUICreate("Nouveau Litige", 531, 438, 192, 123)
GUISetIcon("C:\Users\g056050\Desktop\422.ico", -1)
Global $Lbl_TitreN = GUICtrlCreateLabel("Données du nouveau litige", 64, 20, 450, 41)
GUICtrlSetFont(-1, 24, 800, 0, "MS Sans Serif")
Global $Lbl_NomEmp = GUICtrlCreateLabel("N° De Serie : ", 55, 114, 112, 17)
Global $Inp_NomEmp = GUICtrlCreateInput("", 152, 114, 300, 21)
Global $Lbl_DateDep = GUICtrlCreateLabel("Date du Litige :", 55, 146, 95, 17)
Global $Date_Depart = GUICtrlCreateDate("", 152, 146, 194, 21)
Global $Lbl_Obs = GUICtrlCreateLabel("Observation :", 16, 200, 67, 17)
Global $Edt_Obs = GUICtrlCreateEdit("", 90, 200, 409, 150)
Global $Btn_Valider = GUICtrlCreateButton("VALIDER", 16, 376, 161, 33)
Global $Btn_Retour = GUICtrlCreateButton("RETOUR", 352, 376, 161, 33)
; ############################################## Fin de la création #######################################################################
#endregion

#region Interface Tableau
; ################################# Début de la création de l'interface Tableau ########################################################
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0
                Global $Style = BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)
                Global $Data =  @ScriptDir & "\Data.ini"
                                Global $Data2 =  @ScriptDir & "\Data2.ini"
                Global $F_Tableau = GUICreate("Liste des Empreints", 1074, 645)
                Global $Chk_Seltab = GUICtrlCreateCheckbox("Sélectionner tout", 32, 544, 97, 25)
                Global $Btn_SupprVisu = GUICtrlCreateButton("SUPPRIMER", 368, 596, 161, 33)
                                Global $Btn_OK = GUICtrlCreateButton("LITIGE OK", 168, 544, 161, 33)
                Global $Btn_RetourVisu = GUICtrlCreateButton("RETOUR", 559, 594, 161, 33)
                                Global $Btn_Attente = GUICtrlCreateButton("EN ATTENTE", 169, 593, 161, 33)
                                Global $Btn_Autre = GUICtrlCreateButton("AUTRE", 366, 545, 161, 33)
                                Global $Inp_Autre = GUICtrlCreateInput("", 560, 544, 161, 31)
                                $Pic1 = GUICtrlCreatePic("C:\Users\g056050\Desktop\Capture.jpg", 912, 592, 135, 37)
; ############################################## Fin de la création #######################################################################
#endregion


#region Fonction
;##################### Zone des Fonctions nouveau litige#####################

Func _CreationListView()
    $Section = IniReadSectionNames($Data) ; Lecture des sections
    $hListView = _GUICtrlListView_Create($F_Tableau, "N° De Serie|Date Du Litige|Commentaire|Statut", 10, 6, 1050,520, BitOR($LVS_EDITLABELS, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($hListView,  BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))

    ; Taille des colonnes
    _GUICtrlListView_SetColumnWidth($hListView, 0, 190)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 150)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 625)
    _GUICtrlListView_SetColumnWidth($hListView, 3, 84)





    For $i = 1 To UBound($Section) - 1 ; Boucle de lecture
        $Cle = IniReadSection($Data, $Section[$i]) ; Lecture des clés de la section en cours
        If IsArray($Cle) Then ; Si la section n'est pas vide
            _GUICtrlListView_AddItem($hListView, $Cle[1][1]) ; Récupére valeur de la clé 1 de la section en cours
            _GUICtrlListView_AddSubItem($hListView, $i - 1, $Cle[2][1], 1) ; Récupére valeur de la clé 2 de la section en cours
            _GUICtrlListView_AddSubItem($hListView, $i - 1, $Cle[3][1], 2) ; Récupére valeur de la clé 3 de la section en cours
            _GUICtrlListView_AddSubItem($hListView, $i - 1, $Cle[4][1], 3) ; Récupére valeur de la clé 4 de la section en cours


        EndIf
    Next

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 EndFunc


Func _GUICtrlListView_SetCheckedStates(Const $hListView, Const $iType) ; Fonction des selections des chekbox (0 = Tout Deselectionner , 1 = Tout Selectionner et 2 = Inversion)
    Local $fState = False

    Local Const $iCount = _GUICtrlListView_GetItemCount($hListView)

    If $iType < 0 Or $iType > 2 Then
        Return SetError(1, 0, 0)
    EndIf

    If $iType Then
        $fState = True
    EndIf

    For $i = 0 To $iCount - 1
        If $iType = 2 Then
            $fState = Not _GUICtrlListView_GetItemChecked($hListView, $i)
        EndIf

        _GUICtrlListView_SetItemChecked($hListView, $i, $fState)
    Next
EndFunc

Func _ISCHECKED($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)

    Switch $lParam
        Case $hEdit
            Switch $iCode
                Case $EN_KILLFOCUS
                    Local $iText = _GUICtrlEdit_GetText($hEdit)
                    _GUICtrlListView_SetItemText($hListView, $Item, $iText, $SubItem)
                    ; Après maj de la listView
                    $item = $item + 1
                    $SubItem = $SubItem + 1
                    $Section = IniReadSectionNames($Data) ; Lecture des sections
                    For $i = 1 To UBound($Section) - 1 ; Boucle de lecture
                        If $i = $item Then
                            $Cle = IniReadSection($Data, $Section[$i]) ; Lecture des clés de la section en cours
                            If IsArray($Cle) Then ; Si la section n'est pas vide
                                IniWrite($Data,$Section[$i],$cle[$SubItem][0], $iText)
                            EndIf
                        EndIf
                    Next
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)

                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func FrameRect($hDC, $nLeft, $nTop, $nRight, $nBottom, $hBrush)
    Local $stRect = DllStructCreate("int;int;int;int")

    DllStructSetData($stRect, 1, $nLeft)
    DllStructSetData($stRect, 2, $nTop)
    DllStructSetData($stRect, 3, $nRight)
    DllStructSetData($stRect, 4, $nBottom)

    DllCall("user32.dll", "int", "FrameRect", "hwnd", $hDC, "ptr", DllStructGetPtr($stRect), "hwnd", $hBrush)
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR, $hWndFrom, $iCode

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            Switch $iCode
                Case $NM_DBLCLK
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)

                    If ($aHit[0] <> -1) And ($aHit[1] = 0) Then
                        $Item = $aHit[0]
                        $SubItem = 0
                        Local $aRect = _GUICtrlListView_GetItemRect($hListView, $Item)
                    ElseIf ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                    Else
                        Return $GUI_RUNDEFMSG
                    EndIf

                    Local $iItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                    Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iItemText)
                    $hEdit = _GUICtrlEdit_Create($F_Tableau, $iItemText, $aRect[0] + 3, $aRect[1], $iLen + 10, 17, $Style)

                    _GUICtrlEdit_SetSel($hEdit, 0, -1)
                    _WinAPI_SetFocus($hEdit)
                    $hDC = _WinAPI_GetWindowDC($hEdit)
                    $hBrush = _WinAPI_CreateSolidBrush(0x0000FF)
                    FrameRect($hDC, 0, 0, $iLen + 10 , 17, $hBrush)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc
;##################### Fin de la zone #########################
#endregion


GUISetState(@SW_SHOW, $F_Menu)

#region Boucle Principale
While 1 ; Début de la boucle infinie

    $nMsg = GUIGetMsg() ; Récupération des messages de l'interface
    Switch $nMsg ; Début du sélecteur de cas

        Case $GUI_EVENT_CLOSE ; Si clic fermeture fenêtre, on sort
            MsgBox(64, 'Info', 'Vous avez choisi de fermer la fenêtre en cours') ; Message
            Exit ; Fin du script

; ############################################## Action sur l'interface MENU #############################################################
        Case $Btn_NewPret ; Si clic sur le bouton Nouveau Prêt
            GUISetState(@SW_HIDE, $F_Menu) ; On masque le Menu
            GUISetState(@SW_SHOW, $F_Formulaire) ; On affiche le Formulaire

        Case $Btn_ModifPret ; Si clic sur le bouton Modification
            GUISetState(@SW_HIDE, $F_Menu) ; On masque le Menu

            _CreationListView()

            GUISetState(@SW_SHOW, $F_Tableau) ; On affiche le Tableau

; ######################################## Action sur l'interface Formulaire ################################################################
         Case $Btn_Retour ; Si clic sur le bouton Retour
            GUISetState(@SW_HIDE, $F_Formulaire) ; On masque le Formulaire
            GUISetState(@SW_SHOW, $F_Menu) ; On affiche le Menu

        Case $Btn_Valider ; Si clic sur le bouton Valider
            ; ######################################## Creation des fichiers .ini si inexistant ##############################################################
            If Not FileExists($Data) Then ; Si le fichier Data.ini n'existe pas alors
                FileWrite($Data,"") ; On le crée
            Endif ; Fin SI

            $file = FileOpen($Data, 1) ; On ouvre le fichier Data.ini
            If $file = -1 Then ; Si data.ini n'est pas trouvé alors erreur
                MsgBox(0, "Erreur", "Impossible d'ouvrir le fichier de données.")
                Exit ; Sort du logiciel
                         EndIf ; Fin SI


                        If Not FileExists($Data2) Then ; Si le fichier Data2.ini n'existe pas alors
                FileWrite($Data2,"") ; On le crée
            Endif ; Fin SI

            $file2 = FileOpen($Data2, 1) ; On ouvre le fichier Data2.ini
            If $file2 = -1 Then ; Si data.ini n'est pas trouvé alors erreur
                MsgBox(0, "Erreur", "Impossible d'ouvrir le fichier de données.")
                Exit ; Sort du logiciel
                         EndIf ; Fin SI

            ; ################################################# Fin de l'action ##################################################################

            ; ############################################ Je récupère les valeurs ###############################################################
            Local $val_NomEmp = GUICtrlRead($Inp_NomEmp)
            Local $val_DateDep =GUICtrlRead ($Date_Depart)
            Local $val_Observation = GUICtrlRead ($Edt_Obs)

            ; #################################################### Fin de la récupération ########################################################
            $Statut = "NOK"
                        $Section = IniReadSectionNames($Data) ; Lecture des sections
            $NbSection = UBound($Section)
            $Key1 = "Nom="& $val_NomEmp
            $Key2 = "DateDep="& $val_DateDep
            $Key7 = "Observation="& $val_Observation
            $Key8 = "Recupere="& $Statut


            Local $sData = $Key1 & @LF & $Key2 & @LF & $Key7 & @LF & $Key8
            IniWriteSection($Data, $NbSection, $sData) ;écris le contenu des Key dans le fichier ini Data.ini

            FileClose($file)

            MsgBox(64, "OK", "Le Litige a bien été prise en compte.")
            GUICtrlSetData ($Inp_NomEmp, "") ; On vide la cellule
            GUICtrlSetData ($Date_Depart, "") ; On vide la cellule
            GUICtrlSetData ($Edt_Obs, "") ; On vide la cellule


            ; ################################################## Action sur l'interface Tableau ##################################################
        Case $Chk_Seltab ; Si on coche la case Badgeacce
            If _ISCHECKED($Chk_Seltab) Then ; Si case coche alors
                 _GUICtrlListView_SetCheckedStates($hListView, 1) ; On selectionne tout
            Else ; Sinon
                _GUICtrlListView_SetCheckedStates($hListView, 0) ; Si elle n'est pas coche, On deselectionne tout
            EndIf ; Fin SI

        Case $Btn_SupprVisu ; Si clic sur le bouton Supprimer

            ; Je fais un deselection de toutes les lignes
            $fSelected = False
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            For $i = 0 To $iCount - 1
                _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
            Next

            ; Je compte le nombre de ligne dans le tableau
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            $Section = IniReadSectionNames($Data) - 1 ; Lecture des sections

            ; J'execute une action selon le qui est coché
            For $i = 0 To $iCount - 1
                $Indice = ""
                $Chek = _GUICtrlListView_GetItemChecked($hListView, $i) ; Recupere dans une variable si une ligne est coche ou pas
                If $Chek = True Then ; Si elle est coche alors
                    _GUICtrlListView_SetItemSelected($hListView, $i) ; Je selectionne la ligne
                    $Indice = _GUICtrlListView_GetSelectedIndices($hListView)
                EndIf
                If $Indice <> "" Then
                    $Indice = $Indice + 1

                                  IniDelete($Data,$Section[$Indice]) ;efface dans $Data ce qui a été selectionné

                    _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
                EndIf
            Next

            $Section = IniReadSectionNames($Data) ; Lecture des sections
            For $i = 1 To UBound($Section) - 1
                IniRenameSection($Data,$Section[$i],$i)
            Next

            $contenu=FileRead($Data)
            ;première passe : Cherche plusieurs sauts de lignes depuis le début
            $contenu=StringRegExpReplace($contenu,'\A('&@CRLF&')+','')
            ;deuxième passe : cherche une succession de 2 sauts ou plus successifs pour les remplacer par un seul (sinon les chaînes de textes sont collées)
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&'){2,}',@CRLF)
            ;troisième passe : cherche plusieurs suts de ligne depuis la fin du fichier
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&')+\Z','')
            $hndout=FileOpen(@ScriptDir&"\Data.ini",2)
            FileWrite($hndout,$contenu)
            FileClose($hndout)
            ;### ###

            _GUICtrlListView_Destroy($hListView)
            _CreationListView()

        Case $Btn_RetourVisu ; Si clic sur le bouton Retour
            GUISetState(@SW_HIDE, $F_Tableau) ; On masque le Tableau
            GUISetState(@SW_SHOW, $F_Menu) ; On affiche le Menu
            _GUICtrlListView_Destroy($hListView)

            Case $Btn_Attente ; Si clic sur le bouton Valider
            ; Je fais un deselection de toutes les lignes
            $fSelected = False
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            For $i = 0 To $iCount - 1
                _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
            Next

            ; Je compte le nombre de ligne dans le tableau
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            $Section = IniReadSectionNames($Data) - 1 ; Lecture des sections

            ; J'execute une action selon le qui est coché
            For $i = 0 To $iCount - 1
                $Indice = ""
                $Chek = _GUICtrlListView_GetItemChecked($hListView, $i) ; Recupere dans une variable si une ligne est coche ou pas
                If $Chek = True Then ; Si elle est coche alors
                    _GUICtrlListView_SetItemSelected($hListView, $i) ; Je selectionne la ligne
                    $Indice = _GUICtrlListView_GetSelectedIndices($hListView)
                EndIf
                If $Indice <> "" Then
                    $Indice = $Indice + 1




                                  IniWrite($Data,$Section[$Indice], "Recupere", "EN ATTENTE" )


                    _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
                EndIf
            Next

            $Section = IniReadSectionNames($Data) ; Lecture des sections
            For $i = 1 To UBound($Section) - 1
                IniRenameSection($Data,$Section[$i],$i)
            Next

            $contenu=FileRead($Data)
            ;première passe : Cherche plusieurs sauts de lignes depuis le début
            $contenu=StringRegExpReplace($contenu,'\A('&@CRLF&')+','')
            ;deuxième passe : cherche une succession de 2 sauts ou plus successifs pour les remplacer par un seul (sinon les chaînes de textes sont collées)
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&'){2,}',@CRLF)
            ;troisième passe : cherche plusieurs suts de ligne depuis la fin du fichier
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&')+\Z','')
            $hndout=FileOpen(@ScriptDir&"\Data.ini",2)
            FileWrite($hndout,$contenu)
            FileClose($hndout)
            ;### ###

            _GUICtrlListView_Destroy($hListView)
            _CreationListView()


                 Case $Btn_OK ; Si clic sur le bouton Valider
            ; Je fais un deselection de toutes les lignes
            $fSelected = False
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            For $i = 0 To $iCount - 1
                _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
            Next

            ; Je compte le nombre de ligne dans le tableau
            $iCount = _GUICtrlListView_GetItemCount($hListView)
            $Section = IniReadSectionNames($Data) - 1 ; Lecture des sections

            ; J'execute une action selon le qui est coché
            For $i = 0 To $iCount - 1
                $Indice = ""
                $Chek = _GUICtrlListView_GetItemChecked($hListView, $i) ; Recupere dans une variable si une ligne est coche ou pas
                If $Chek = True Then ; Si elle est coche alors
                    _GUICtrlListView_SetItemSelected($hListView, $i) ; Je selectionne la ligne
                    $Indice = _GUICtrlListView_GetSelectedIndices($hListView)
                EndIf
                If $Indice <> "" Then
                    $Indice = $Indice + 1


                                  IniWrite($Data,$Section[$Indice], "Recupere", "OK" ) ; change la clef "recupere" dans $Data
                                  $Temp = IniReadSection($Data,$Section[$Indice])
                                  IniWriteSection($Data2,$Section[$Indice] ,$Temp)
                                  IniDelete($Data,$Section[$Indice]) ;efface dans $Data ce qui a été selectionné




                    _GUICtrlListView_SetItemSelected($hListView, $i, $fSelected = True)
                EndIf
            Next

            $Section = IniReadSectionNames($Data) ; Lecture des sections
            For $i = 1 To UBound($Section) - 1
                IniRenameSection($Data,$Section[$i],$i)
            Next

            $contenu=FileRead($Data)
            ;première passe : Cherche plusieurs sauts de lignes depuis le début
            $contenu=StringRegExpReplace($contenu,'\A('&@CRLF&')+','')
            ;deuxième passe : cherche une succession de 2 sauts ou plus successifs pour les remplacer par un seul (sinon les chaînes de textes sont collées)
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&'){2,}',@CRLF)
            ;troisième passe : cherche plusieurs suts de ligne depuis la fin du fichier
            $contenu=StringRegExpReplace($contenu,'('&@CRLF&')+\Z','')
            $hndout=FileOpen(@ScriptDir&"\Data.ini",2)
            FileWrite($hndout,$contenu)
            FileClose($hndout)
            ;### ###

            _GUICtrlListView_Destroy($hListView)
            _CreationListView()


    EndSwitch ; Fin du sélecteur de cas
WEnd ; Fin de la boucle infinie
#endregion
Fichiers joints
MCO2.au3
(21.23 Kio) Téléchargé 116 fois
Avatar du membre
mikell
Spammer !
Spammer !
Messages : 6292
Enregistré le : dim. 29 mai 2011 17:32
Localisation : Deep Cévennes
Status : Hors ligne

Re: ne pouvoir selectionner qu'une seule checkbox

#2

Message par mikell »

Pas moyen avec des checkbox. Ou plutôt, trop compliqué et j'ai pas le courage :mrgreen:
Mais mais ... il existe un autre moyen :

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

   
    GUICreate("ListView Set Item State", 400, 300)
    $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
    _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_SUBITEMIMAGES))
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; Load images
    $hImage = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_AddIcon($hImage, "shell32.dll", 137)
    _GUICtrlListView_SetImageList($hListView, $hImage, 2)

    ; Add columns
    _GUICtrlListView_AddColumn($hListView, "Column 1", 120)
    _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
    _GUICtrlListView_AddColumn($hListView, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()


Func _ListView_Click($hWnd, $iIndex)
    For $i = 0 to _GUICtrlListView_GetItemCount($hListView) -1
       If $i = $iIndex Then
       If _GUICtrlListView_GetItemStateImage($hWnd, $iIndex) = 1 Then
           _GUICtrlListView_SetItemStateImage($hListView, $iIndex, 0)
       Else
           _GUICtrlListView_SetItemStateImage($hListView, $iIndex, 1)
       EndIf
      Else
           _GUICtrlListView_SetItemStateImage($hListView, $i, 0)
      EndIf
    Next
EndFunc   ;==>_ListView_Click


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_CLICK
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    Local $iIndex = DllStructGetData($tInfo, "Index")
                    If $iIndex <> -1 Then
                        Local $iX = DllStructGetData($tInfo, "X")
                        Local $aIconRect = _GUICtrlListView_GetItemRect($hListView, $iIndex, 1)
                        If $iX < $aIconRect[0] And $iX >= 5 Then
                            _ListView_Click($hWndListView, $iIndex)
                            Return 0
                        EndIf
                    EndIf
             EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
" L'échec est le fondement de la réussite. " (Lao-Tseu )
" Plus ça rate, plus on a de chances que ça marche " (les Shadoks )
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: ne pouvoir selectionner qu'une seule checkbox  

#3

Message par yohanb767 »

merci pour ton aide mikell !
Répondre