Jump to content
Sign in to follow this  
NBenitus

Get children text in ControlTreeView object

Recommended Posts

NBenitus

Hi all,

Here is the situation. I have the following tree view:

Parent (Only one parent with name "Server")

- Children 1

- Children 2

- Children 3

My goal is to go to through each children and get the text.

I read the page http://www.autoitscript.com/autoit3/docs/f...rolTreeView.htm, but I still can't figure out how to do it as I don't know how to reach the children nor get the children text, even after many attempts.

Any help would be greatly appreciated.

Sincerely,

B.

Share this post


Link to post
Share on other sites
bo8ster

I would suggest the following.

You can work out the syntax

Get Handle to the Control (ControlGetHandle) and then test to make sure you have it - call it $hwd

$aChildNames

For $i = 0 to ControlTreeView($hwd, , , "GetItemCount")

_ArrayAdd($aChildNames, ControlTreeView($hwd, , , "GetText", $i))

Next

_ArrayDisplay($aChildNames)

You might want to put some error checking in or ConsoleWrite the return string of ControlTreeView($hwd, , , "GetText", $i) to see if you are on the right track.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
NBenitus

I would suggest the following.

You can work out the syntax

Get Handle to the Control (ControlGetHandle) and then test to make sure you have it - call it $hwd

$aChildNames

For $i = 0 to ControlTreeView($hwd, , , "GetItemCount")

_ArrayAdd($aChildNames, ControlTreeView($hwd, , , "GetText", $i))

Next

_ArrayDisplay($aChildNames)

You might want to put some error checking in or ConsoleWrite the return string of ControlTreeView($hwd, , , "GetText", $i) to see if you are on the right track.

Thanks a lot, I will try that :D .

Share this post


Link to post
Share on other sites
NBenitus

I am unsure how to test if I got the handle correctly or not. Here's the modified code with your suggestions:

$hwd = ControlGetHandle("server2", "", "[CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]")

For $i = 0 to ControlTreeView("server2", "", $hwd, "GetItemCount")

ConsoleWrite(ControlTreeView("server2", "", $hwd, "GetText", $i))

Next

Unfortunately, it is still not working :D .

Share this post


Link to post
Share on other sites
NBenitus

After investigation, the method "GetItemCount" always return me "1" even if I have four children. Am I missing something?

Edited by NBenitus

Share this post


Link to post
Share on other sites
bo8ster

You really want to make sure you get the handle (and the correct one). I would do ConsoleWrite("The Handle is " & $hwd) (or u can use a msgbox) just after the ControlGetHandle command. Then compare this to the handle shown in the (Summary Tab) Control Section of the Info Tool. There will be two handles, one for the window and one for the control. Can you copy the out put of the Info Tool.

Reading the help file more closely, ConsoleWrite(ControlTreeView("server2", "", $hwd, "GetText", $i)) will not work. You have to use "Root|Item 1" or something for the item to get the child count.

Firstly make sure you get the handle then try to get the count of the sub items.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
NBenitus

You really want to make sure you get the handle (and the correct one). I would do ConsoleWrite("The Handle is " & $hwd) (or u can use a msgbox) just after the ControlGetHandle command. Then compare this to the handle shown in the (Summary Tab) Control Section of the Info Tool. There will be two handles, one for the window and one for the control. Can you copy the out put of the Info Tool.

Reading the help file more closely, ConsoleWrite(ControlTreeView("server2", "", $hwd, "GetText", $i)) will not work. You have to use "Root|Item 1" or something for the item to get the child count.

Firstly make sure you get the handle then try to get the count of the sub items.

Thanks for your help.

It seems I have the correct handle, it matches the handle listed in the Control section of the Window Info window. The following line still displays 1 children:

$hwd = ControlGetHandle("server2 - VMware Infrastructure Client", "", "[CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]")

ConsoleWrite("The number of children is " & ControlTreeView("server2", "", $hwd, "GetItemCount"))

For the output:

>>>> Control <<<<

Class: WindowsForms10.SysTreeView32.app.0.259f9d2

Instance: 1

ClassnameNN: WindowsForms10.SysTreeView32.app.0.259f9d21

Advanced (Class): [CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]

ID: 9507150

Text:

Position: 2, 91

Size: 196, 211

ControlClick Coords: 90, 70

Style: 0x5601002D

ExStyle: 0x00000000

Handle: 0x0091114E

Note: The ID and Handle keeps changing when I open the application.

Thanks again :D .

Share this post


Link to post
Share on other sites
PsaltyDS

Thanks for your help.

It seems I have the correct handle, it matches the handle listed in the Control section of the Window Info window. The following line still displays 1 children:

$hwd = ControlGetHandle("server2 - VMware Infrastructure Client", "", "[CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]")

ConsoleWrite("The number of children is " & ControlTreeView("server2", "", $hwd, "GetItemCount"))

<snip>

Note: The ID and Handle keeps changing when I open the application.

Thanks again :D .

Try this:
#Include <GuiTreeView.au3>

$hWin = WinGetHandle("server2 - VMware Infrastructure Client", "")
$sTVClass = "[CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]"
$hTV = ControlGetHandle($hWin, "", $sTVClass)
$iTVCnt = _GUICtrlTreeView_GetCount($hTV)
ConsoleWrite("The number of children is " & $iTVCnt)

:D

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
NBenitus

Try this:

#Include <GuiTreeView.au3>

$hWin = WinGetHandle("server2 - VMware Infrastructure Client", "")
$sTVClass = "[CLASS:WindowsForms10.SysTreeView32.app.0.259f9d2; INSTANCE:1]"
$hTV = ControlGetHandle($hWin, "", $sTVClass)
$iTVCnt = _GUICtrlTreeView_GetCount($hTV)
ConsoleWrite("The number of children is " & $iTVCnt)

:D

There is some progress, now it returns me 2 children, but I still have four ...

Stupid tree view ...

But thanks for the help PsaltyDS !

Edited by NBenitus

Share this post


Link to post
Share on other sites
bo8ster

The ID and Handle changes each time because they are dynamic, thats why you have to use other properties of control that are static.

I don't know GuiTreeView.au3 so I can't help there but PsaltyDS knows just about everything! :D


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
PsaltyDS

There is some progress, now it returns me 2 children, but I still have four ...

Stupid tree view ...

But thanks for the help PsaltyDS !

Does this look like your treeview? And if not, what's different?

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

Global $hItem, $hTreeView, $hTVParent
Global $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _
        $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

GUICreate("TreeView Get Count", 400, 300)
$hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()

$hTVParent = _GUICtrlTreeView_Add($hTreeView, 0, "Server")
For $x = 1 To 3
    _GUICtrlTreeView_AddChild($hTreeView, $hTVParent, "Children " & $x)
Next
_GUICtrlTreeView_Expand($hTreeView, $hTVParent, True)

ConsoleWrite("Count: " & _GUICtrlTreeView_GetCount($hTreeView) & @LF)

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

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
NBenitus

Yes, that looks like my tree view.

I tried the GetSelected method and it always return me 0. Maybe it's a list view in a tree view?

Edited by NBenitus

Share this post


Link to post
Share on other sites
bo8ster

I would think it is by the class name but post a screen shot of the control anyway.

PsaltyDS, is there a way to get more control info?


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites
Melba23

dsk,

Welcome to the AutoIt forum. :oops:

To reply in a thread you use the "Reply to this topic" button at the top or the "Reply to this topic" editor at the bottom. The "Report" button you pressed is only for alerting the Mods to a problem - that is why your post has not appeared. :doh:

You will also notice that this this thread is nearly 3 years old. We discourage "necro-posting" as the language has evolved a lot over the past few years and it is quite likely that there is a better way of doing things than was the case in the past. It is best to open a new thread rather then reopen one from a few years back. ;)

Look forward to seeing your new thread soon. :bye:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

×