Get All Text From A TreeView Control
Posted: 18 Sep 2021, 17:50
So I've been searching and I havent found a clear way of getting the text from a treeview control, I ended up developing my own function but it only grabs the first generation of children, but not their children
I've had the idea of storing it in an array, an associative one, but I don't think it would work, my function was somewhat inspired on how the ControlGet, List, ListView works
I've also had the idea of storing it like this:
Fruits[Apples[Red, Circular, Hard], Oranges[Orange, Circular, Squishy]]
And it would get that from the TreeView in the image below
I really dont know any other way of doing it, and I've had this problem for a couple of months now, any help would be appreciated!
I've had the idea of storing it in an array, an associative one, but I don't think it would work, my function was somewhat inspired on how the ControlGet, List, ListView works
I've also had the idea of storing it like this:
Fruits[Apples[Red, Circular, Hard], Oranges[Orange, Circular, Squishy]]
And it would get that from the TreeView in the image below
Code: Select all
TV_GetTextAll(TreeViewName := "SysTreeView321") {
Gui, TreeView, %TreeViewName%
ItemID := 0 ; Causes the loop's first iteration to start the search at the top of the tree.
Loop
{
ItemID := TV_GetNext(ItemID, "Full") ; Replace "Full" with "Checked" to find all checkmarked items.
if not ItemID ; No more items in tree.
break
if not TV_GetParent(ItemID) ; Checks if the item is a parent, if so it stores the text in %ParentText% for later (only works with the top level however).
TV_GetText(ParentText, ItemID)
else ; Checks if the item is a child, if so it stores the text in %ChildText% for later.
{
TV_GetText(Child, ItemID)
ChildText .= Child "|"
TempItemID := TV_GetNext(ItemID, "Full")
if not TV_GetParent(TempItemID)
List .= ParentText "="ChildText "`n"
}
}
return RTrim(List, "`n" "|")
}