Jump to content
Sign in to follow this  
Belini

Selecionar linha em TreeView enviando letra

Recommended Posts

Preciso selecionar linhas no TreeView enviando a letra para selecionar a linha iniciada com ela mas não consegui usando Send() e ControlSend() alguém tem alguma dica?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Test()

Func Test()
    Local $treeview, $i, $letter[27]
    GUICreate("Treeview", 210, 420)
    $treeview = GUICtrlCreateTreeView(0, 0, 210, 420, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    For $i = 1 To 26
        $letter[$i] = StringUpper(Chr(64 + $i))
        GUICtrlCreateTreeViewItem($letter[$i], $treeview)
    Next
    _GUICtrlTreeView_SelectItem($treeview, _GUICtrlTreeView_GetFirstItem($treeview))
    GUISetState()

    While 1
        For $i = 1 To 26
            Send($letter[$i]); Não seleciona a linha quando envio a letra
            Sleep(100)
        Next
    WEnd
EndFunc   ;==>Test

 

Share this post


Link to post
Share on other sites

Seria isso @Belini ?

#cs
    Test()

    Func Test()
    Local $treeview, $i, $letter[27]
    GUICreate("Treeview", 210, 420)
    $treeview = GUICtrlCreateTreeView(0, 0, 210, 420, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    For $i = 1 To 26
    $letter[$i] = StringUpper(Chr(64 + $i))
    GUICtrlCreateTreeViewItem($letter[$i], $treeview)
    Next
    _GUICtrlTreeView_SelectItem($treeview, _GUICtrlTreeView_GetFirstItem($treeview))
    GUISetState()

    While 1
    For $i = 1 To 26
    Send($letter[$i]); Não seleciona a linha quando envio a letra
    Sleep(100)
    Next
    WEnd
    EndFunc   ;==>Te
#CE

;~ #AutoIt3Wrapper_AU3Check_Parameters= -q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7
;~ #Tidy_Parameters=/sf

#include-once
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

OnAutoItExitRegister("OnExit")

Opt("GUIOnEventMode", 1)
Opt("GUIEventOptions", 1)
Opt("MustDeclareVars", 1)

Global $aGuiSize[2] = [800, 600]
Global $sGuiTitle = "GuiTitle"
Global $hGui
Global $iTreeView
Global $sLetter
Global $iSearch, $hItem

$hGui = GUICreate($sGuiTitle, $aGuiSize[0], $aGuiSize[1])
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$iTreeView = GUICtrlCreateTreeView(10, 10, 210, 420, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
For $ii = 1 To 26
    $sLetter = StringUpper(Chr(64 + $ii))
    GUICtrlCreateTreeViewItem($sLetter, $iTreeView)
Next

GUISetState(@SW_SHOW, $hGui)

For $ii = 1 To 26
    $sLetter = StringUpper(Chr(64 + $ii))
    $iSearch = _GUICtrlTreeView_FindItem($iTreeView, $sLetter)
    If Not @error Then
        $hItem = _GUICtrlTreeView_GetItemHandle($iTreeView, $iSearch)
        _GUICtrlTreeView_SelectItem($iTreeView, $hItem, $TVGN_FIRSTVISIBLE)
        _GUICtrlTreeView_SetState($iTreeView, $hItem, $TVIS_SELECTED, True)
    EndIf
Next

While Sleep(25)
WEnd

Func OnExit()
    GUISetState($hGui, @SW_HIDE)
    GUIDelete($hGui)
EndFunc   ;==>OnExit

Func Quit()
    Exit
EndFunc   ;==>Quit

 

Share this post


Link to post
Share on other sites

@Luigi eu preciso selecionar uma por vez e também que seja selecionado se for mais de um caractér em cada linha, neste exemplo que vc fez seleciona todas e se eu colocar mais um caractér na linha não seleciona nenhuma.

 

For $ii = 1 To 26
    $sLetter = StringUpper(Chr(64 + $ii)) & $ii
    GUICtrlCreateTreeViewItem($sLetter, $iTreeView)
Next

Até me indicaram um comando que seleciona uma por vez mas também só funciona se tiver apenas uma letra na linha.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>

Test_1()
Test_2()

Func Test_1()
    Local $treeview, $i, $Gui, $letter[27]
    $Gui = GUICreate("Treeview", 210, 420)
    $treeview = GUICtrlCreateTreeView(0, 0, 210, 420, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    For $i = 1 To 26
        $letter[$i] = StringUpper(Chr(64 + $i))
        GUICtrlCreateTreeViewItem($letter[$i], $treeview)
    Next
    _GUICtrlTreeView_SelectItem($treeview, _GUICtrlTreeView_GetFirstItem($treeview))
    GUISetState()

    For $i = 1 To 26
        ControlTreeView("Treeview", "", $treeview, "Select", $letter[$i])
        Sleep(11)
    Next
    GUIDelete($Gui)
EndFunc   ;==>Test_1

Func Test_2()
    Local $treeview, $i, $Gui, $letter[27]
    $Gui = GUICreate("Treeview", 210, 420)
    $treeview = GUICtrlCreateTreeView(0, 0, 210, 420, BitOR($TVS_HASLINES, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    For $i = 1 To 26
        $letter[$i] = StringUpper(Chr(64 + $i))
        GUICtrlCreateTreeViewItem($letter[$i] & $i, $treeview)
    Next
    _GUICtrlTreeView_SelectItem($treeview, _GUICtrlTreeView_GetFirstItem($treeview))
    GUISetState()

    While 1
        For $i = 1 To 26
            ControlTreeView("Treeview", "", $treeview, "Select", $letter[$i])
            Sleep(11)
        Next
    WEnd
EndFunc   ;==>Test_2

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×