Jump to content

Treeview to editbox by ControlClick


Jayson
 Share

Recommended Posts

Hello everyone ! I would like to know if there's a better way to send a text from a treeview to an editbox.

By clicking any item in my treeview it get a selected array to display in the editbox by Send() BUT the problem is the ControlClick looks like to get the middle of the control to send the text.

Like if theres 10 lines and 20 rows it will send the text at 5,10 or when it can't reach the middle it start in the middle line until the text reach the middle then it write from that point.

What's wrong with this ?

Sorry for my bad english ;)

Edited by Jayson
Link to comment
Share on other sites

  • Moderators

Jayson,

You have been here long enough to know that you need to post some code if you want help - particularly if the problem is a cryptic as that one appears to be! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

Sorry, I forgot to post an example ;)

Make about 30 lines, click on line 5 then double click 2 times the first subitem in the treeview (HREF="").

It will automatically write at line 17 and on the second double click the text won't appear at the end of the first one.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIEdit.au3>
#include <GuiTreeView.au3>
#include <Constants.au3>
#include <File.au3>
Global $aTab[2] = [0], $aEdit[2], $aEditDisable[2]
Global $iCounter = 0
Global $aData[3][4] = [ _
    ['<A ...>', '<A ...>', '',''], _
    ['<A ...>', 'HREF=""', 'URL you are linking to.' & @LF & 'Example :' & @CRLF & '<A HREF="resumepage.html">my resume</A>','<A HREF="resumepage.html">my resume</A>'], _
    ['<A ...>', 'NAME=""', 'Name a section of the page.' & @CRLF & 'Example :' & @CRLF & '','']]


Global $sLineCount = ''
For $i = 1 To 2000
    $sLineCount &= $i & @CRLF
Next

$Editor = GUICreate('Editor', 800, 600, 0, 0, BitOR($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX))

$NewTabButton = GUICtrlCreateButton('+', 475, 10, 50, 20)
$DelTabButton = GUICtrlCreateButton('-', 420, 10, 50, 20)
$Tags = GUICtrlCreateTreeView(20, 95, 125, 100, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$TagsHandle = GUICtrlGetHandle($Tags)
$Tab = GUICtrlCreateTab(200, 95, 550, 430)
GUISetState()
_AddTab()

$sParent = ''
For $i = 0 To UBound($aData) - 1
    If $aData[$i][0] <> $sParent Then
    $sParent = $aData[$i][0]
    $hParent = GUICtrlCreateTreeViewItem($aData[$i][0], $Tags)
    EndIf
    If $aData[$i][1] <> $sParent Then $hChild = GUICtrlCreateTreeViewItem($aData[$i][1], $hParent)
Next

GUIRegisterMsg($WM_CTLCOLOREDIT, 'WM_CTLCOLOREDIT')
GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')

While 1
    Switch GUIGetMsg()

        Case $DelTabButton
            _DelTab()

        Case $NewTabButton
            _AddTab()

        Case $GUI_EVENT_CLOSE
            ExitLoop
            Exit

    EndSwitch
WEnd

Func _AddTab()
    $iCounter += 1
    $aTab[0] += 1
    ReDim $aTab[$aTab[0] + 1]
    $aTab[$aTab[0]] = GUICtrlCreateTabItem($aTab[0])
    ReDim $aEdit[$aTab[0] + 1]
    $aEdit[$aTab[0]] = GUICtrlCreateEdit('', 270, 122, 450, 400)
    GUICtrlSetFont(-1, 8,800, 'Tahoma')
    ReDim $aEditDisable[$aTab[0] + 1]
    $aEditDisable[$aTab[0]] = GUICtrlCreateEdit('1', 208, 122, 55, 400, BitOR($ES_READONLY, $ES_CENTER))
    GUICtrlSetFont(-1, 8,800, 'Tahoma')
    GUICtrlCreateTabItem('')
EndFunc ;==>_AddTab

Func _DelTab()
    $DelTab = GUICtrlRead($Tab, 1)
    If $DelTab <> 0 Then
        Local $iIndex = _ArraySearch($aTab, $DelTab)
        If $iIndex <> -1 Then
            GUICtrlDelete($aEdit[$iIndex])
            _ArrayDelete($aEdit, $iIndex)
            GUICtrlDelete($aTab[$iIndex])
            _ArrayDelete($aTab, $iIndex)
            GUICtrlDelete($aEditDisable[$iIndex])
            _ArrayDelete($aEditDisable, $iIndex)
            $aTab[0] -= 1
        EndIf
    EndIf
EndFunc ;==>_DelTab

Func WM_CTLCOLOREDIT($hWnd, $iMsg, $iWParam, $iLParam)
    Global $ActiveTab = GUICtrlRead($Tab) + 1
    If $iLParam = GUICtrlGetHandle($aEdit[$ActiveTab]) Then
        ;_GUICtrlEdit_BeginUpdate($aEditDisable[$ActiveTab])
        Local $iLineCount = _GUICtrlEdit_GetLineCount($aEdit[$ActiveTab])
        Local $iCutOff = StringInStr($sLineCount, @CRLF, 0, $iLineCount)
        If $iCutOff = 0 Then
            ;Global $sLineCount = ''
            For $i = 1 To $iLineCount + 100
                $sLineCount &= $i & @CRLF
            Next
            $iCutOff = StringInStr($sLineCount, @CRLF, 0, $iLineCount)
        EndIf
        GUICtrlSetData($aEditDisable[$ActiveTab], StringLeft($sLineCount, $iCutOff + 1))
        Local $iLineVis = _GUICtrlEdit_GetFirstVisibleLine($aEdit[$ActiveTab])
        _GUICtrlEdit_LineScroll($aEditDisable[$ActiveTab], 0, $iLineVis)
        ;_GUICtrlEdit_EndUpdate($aEditDisable[$ActiveTab])
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_CTLCOLOREDIT

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $ActiveTab = GUICtrlRead($Tab) + 1
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
    $iCode = DllStructGetData($tNMHDR, 'Code')
    Switch $hWndFrom
    Case $TagsHandle
    Switch $iCode
    Case $NM_DBLCLK
                    $TagsSelected = _GUICtrlTreeView_GetSelection($Tags)
                    $TagsText = _GUICtrlTreeView_GetText($Tags, $TagsSelected)
                    $iiIndex = _ArraySearch($aData, $TagsText, 0, 0, 0, 0, 1, 1)
                    $TagsText = $aData[$iiIndex][3]
                    $aEditText = GUICtrlRead($aEdit[$ActiveTab])
                    ControlClick('Editor', $aEditText, $aEdit[$ActiveTab])
                    ;ControlSend ( "Editor", $aEditText, $aEdit[$ActiveTab], $TagsText)
                    Send($TagsText)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY

Edit : Typnig !

Edited by Jayson
Link to comment
Share on other sites

  • Moderators

Jayson,

The edit control is one you have created - all you need to do is use GUICtrlSetData and use the "default" parameter to insert at the caret point. But you have to select the caret position each time so AutoIt knows where to put the text. :)

Change your WM_NOTIFY handler to this:

Switch $iCode
    Case $NM_DBLCLK
        $TagsSelected = _GUICtrlTreeView_GetSelection($Tags)
        $TagsText = _GUICtrlTreeView_GetText($Tags, $TagsSelected)
        $iiIndex = _ArraySearch($aData, $TagsText, 0, 0, 0, 0, 1, 1)
        $TagsText = $aData[$iiIndex][3]
        GUICtrlSetData($aEdit[$ActiveTab], $TagsText, " ")
EndSwitch

Now I get the text inserted each time I double-click on the TreeView HREF="" item - as long as I have set the caret position in the editor beforehand. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...