Selection des données avec $LVS_EDITLABELS

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

Selection des données avec $LVS_EDITLABELS

#1

Message par yohanb767 »

Bonjour ,

Dans un de mes scripts j'ai créer un tableau

voici le morceau du script

Func _CreationListView()
$Section = IniReadSectionNames($Data) ; Lecture des sections
$hListView = _GUICtrlListView_Create($F_Tableau, "N° De Serie|Client/ARM|Date|Statut|Commentaire", 10, 12, 1050,500, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))


j'arrive bien a éditer les données dans le tableau via $LVS_EDITLABELS mais le soucis c'est que quand je double clic sur la données que je veux modifier , elles sont automatiquement Sélectionnées (surbrillance bleu)

y a t'il un moyen qu'elles ne soient pas sélectionnées lors de l'Edition car si l'on rajoute quelque chose cela efface la sélection

j'espère avoir été claire dans ma demande
Merci d'avance
Avatar du membre
DimVar
Niveau 10
Niveau 10
Messages : 867
Enregistré le : ven. 30 mai 2008 15:08
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#2

Message par DimVar »

Bonjour,


Peut etre voir les parametres de la fonction (iExStyle)

Cdlt.
Dimvar.
N'évoquons pas la pierre, les jeunes risqueraient d'en poire !
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#3

Message par yohanb767 »

Je viens de regarder mais je ne vois grand chose
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#4

Message par yohanb767 »

Voici ce que cela me donne quand je doucble clic en utilisant la fonction $LVS_EDITLABELS



Sans titre2.png
Sans titre2.png (3.64 Kio) Vu 3991 fois




et voici ce que je souhaiterai si cela est possible




Sans titre1.png
Sans titre1.png (3.3 Kio) Vu 3991 fois


Car lors d'une frappe sur le clavier cela efface directement ce qui été écris
Avatar du membre
DimVar
Niveau 10
Niveau 10
Messages : 867
Enregistré le : ven. 30 mai 2008 15:08
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#5

Message par DimVar »

A moins d'ajouter un clic après le double clic, en effet, je ne vois pas trop.
N'évoquons pas la pierre, les jeunes risqueraient d'en poire !
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#6

Message par yohanb767 »

ajouter un clic pas top tout ca et de plus je ne peux même pas le rajouter
la je sèche

si quelqu'un a une piste
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#7

Message par walkson »

Bonjour,
Il y a plusieurs méthodes pour éditer une LV
Je devine d'après les images que vous utilisez un édit temporaire. Si c'est le cas, il suffit de rajouter juste après sa création GUICtrlSetState($EditTemporaire, $GUI_FOCUS)
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#8

Message par yohanb767 »

Bonjour Walkson !

je viens d'essayer mais sans succès hélas , ci joint mon bout de code
Func _CreationListView()

    $Section = IniReadSectionNames($Data) ; Lecture des sections
    $hListView = _GUICtrlListView_Create($F_Tableau, "N° De Serie|Client/ARM|Date|Statut|Commentaire", 10, 12, 1050,500, BitOR($LVS_EDITLABELS, $LVS_REPORT))

    _GUICtrlListView_SetExtendedListViewStyle($hListView,  BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))


         Local $maxCheck = 1
         Local $nbCheck = 0

     ; Si l'on coche une case.
     If (GUICtrlRead($hListView) = $GUI_CHECKED) Then
         ; On incrémente le nombre de cases cochées.
         $nbCheck += 1
         MsgBox(64, 'Info', $nbCheck)
       EndIf



    ; Taille des colonnes
   _GUICtrlListView_SetColumnWidth($hListView, 0, 150)
    _GUICtrlListView_SetColumnWidth($hListView, 1, 75)
    _GUICtrlListView_SetColumnWidth($hListView, 2, 75)
    _GUICtrlListView_SetColumnWidth($hListView, 3, 85)
   _GUICtrlListView_SetColumnWidth($hListView, 4, 1000)





    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
         _GUICtrlListView_AddSubItem($hListView, $i - 1, $Cle[5][1], 4) ; Récupére valeur de la clé 4 de la section en cours


        EndIf
    Next


 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)
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#9

Message par walkson »

remplacez _GUICtrlEdit_SetSel($hEdit, 0, -1) par _GUICtrlEdit_SetSel($hEdit, $iLen, $iLen) dans Func WM_NOTIFY
$iLen étant la longueur du text (en pixel mais c'est pas grave, ça donne de la marge :mrgreen: )
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS  

#10

Message par yohanb767 »

Merci Walkson tu me retire une épine du pieds !

cela fait une semaine que je but et que je cherche une solution sur la toile

bonne journée et encore merci
Avatar du membre
walkson
Modérateur
Modérateur
Messages : 1020
Enregistré le : ven. 12 août 2011 19:49
Localisation : Hurepoix
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#11

Message par walkson »

Pour le faire en plus propre (en comptant le nombre de lettres)

Code : Tout sélectionner

#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <GuiEdit.au3>

Global $hGuui, $hListView
Global $hEdit, $hDC, $hBrush, $Item = -1, $SubItem = 0

$hGUI = GUICreate("ListView Subitems edit in place", 300, 200)
$hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|SSubitem", 2, 2, 296, 196, BitOR($LVS_EDITLABELS, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_GRIDLINES)
For $i = 1 To 10
    _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1)
	_GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 2)
Next
GUISetState(@SW_SHOW, $hGuui)

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

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

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 ; used for sub item edit
                    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
                    If ($aHit[0] <> -1) And ($aHit[1] > 0) Then
                        $Item = $aHit[0]
                        $SubItem = $aHit[1]
                        Local $iSubItemText = _GUICtrlListView_GetItemText($hListView, $Item, $SubItem)
                        Local $iLen = _GUICtrlListView_GetStringWidth($hListView, $iSubItemText)
                        Local $aRect = _GUICtrlListView_GetSubItemRect($hListView, $Item, $SubItem)
                        $hEdit = _GUICtrlEdit_Create($hGUI, $iSubItemText, $aRect[0] + 6, $aRect[1], $iLen + 10, 17, BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT))
						;_GUICtrlEdit_SetSel($hEdit, 0, -1)
						$nb = _GUICtrlEdit_GetTextLen ( $hEdit ); compte le nb de letttres
                        _GUICtrlEdit_SetSel($hEdit, $nb, $nb) ; focus à la fin du texte
                        _WinAPI_SetFocus($hEdit)
                        $hDC = _WinAPI_GetWindowDC($hEdit)
                        $hBrush = _WinAPI_CreateSolidBrush(0)
                        FrameRect($hDC, 0, 0, $iLen + 10, 17, $hBrush)
                    EndIf
                Case $LVN_ENDLABELEDITW ; Used for 1st column edit
                    Local $tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
                    Local $tBuffer = DllStructCreate("char Text[" & DllStructGetData($tInfo, "TextMax") & "]", DllStructGetData($tInfo, "Text"))
                    If StringLen(DllStructGetData($tBuffer, "Text")) Then Return True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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   ;==>FrameRect

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)
                    _WinAPI_DeleteObject($hBrush)
                    _WinAPI_ReleaseDC($hEdit, $hDC)
                    _WinAPI_DestroyWindow($hEdit)
                    $Item = -1
                    $SubItem = 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
yohanb767
Niveau 5
Niveau 5
Messages : 117
Enregistré le : mer. 28 déc. 2016 14:09
Status : Hors ligne

Re: Selection des données avec $LVS_EDITLABELS

#12

Message par yohanb767 »

merci
Répondre