I have a TreeView where you double click an item and it is supposed to return the keystrokes you'd use to get to that item from the root in a collapsed TreeView. It's necessary to get the keystrokes to get to the item because the real TreeView is in another program that uses custom controls that don't respond to any messages, and the only way I've found to navigate it reliably is by sending keystrokes.
In the image above to when you double click "C-2" it should return "{down}{right}{down 3}{right}{down 2}" (the keys you'd press to get to the item from the root of a collapsed treeview) It doesn't matter if it consolidates {down}{down} into {down 2} or anything.
I've been at it for a while and I just can't get it. I've left out my code for ReturnShortcut() below because it doesn't work and I don't want to confuse anyone.
I've also included the function GetItemType(ItemID) which will tell you what type of item ItemID is.
Any help is greatly appreciated!
Code:
Gui, Add, TreeView, R10 gTreeView
P1 := TV_Add("A")
P1C1 := TV_Add("A-1", P1)
P2 := TV_Add("B")
P2C1 := TV_Add("B-1", P2)
P2C2 := TV_Add("B-2", P2)
P3 := TV_Add("C" , P2)
P3C1 := TV_Add("C-1", P3)
P3C2 := TV_Add("C-2", P3)
P4 := TV_Add("D")
P4C1 := TV_Add("D-1", P4)
P4C2 := TV_Add("D-1", P4)
Gui, Show
return
TreeView:
If (A_GuiEvent = "DoubleClick")
{
ItemID := TV_GetSelection()
RetVal := ReturnShortcut(ItemID)
Msgbox %Retval%
}
return
ReturnShortcut(ItemID, PathString = "")
{
}
;<doc>
;
; Function: GetItemType
; Description:
; Returns what type of item is selected in the TreeView.
; Syntax: GetItemType(ItemID)
; Parameters:
; ItemID - The ItemID of the selected item in the TreeView.
; Return Value:
; TopParent - The item is the topmost parent in the tree.
; Parent - The item is a parent item in the treeview, but not the topmost.
; LowerParent - The item is a parent item but has another parent item above it in the tree.
; TopChild - The item is the topmost child in a section.
; Child - The item is a child but not the topmost and it does have a parent.
; SingleChild - The item is a child but it does not have a parent item in the tree.
; Remarks:
; This function uses the ItemID to get the parent item, the previous item, and the child item and determine what type of item is selected.
; See the Return Values section for the different types of items.
; Example:
; ItemID := TV_GetSelection()
; ItemType := GetItemType(ItemID)
;
;</doc>
GetItemType(ItemID)
{
ParentItemID := TV_GetParent(ItemID)
PrevItemID := TV_GetPrev(ItemID)
ChildItemID := TV_GetChild(ItemID)
If (ParentItemID = 0 and ChildItemID != 0 and PrevItemID = 0)
return "TopParent"
else if (ParentItemID = 0 and ChildItemID != 0 and PrevItemID != 0)
return "Parent"
else if (ParentItemID != 0 and ChildItemID != 0 and PrevItemID != 0)
return "LowerParent"
else if (ParentItemID != 0 and ChildItemID = 0 and PrevItemID = 0)
return "TopChild"
else if (ParentItemID != 0 and ChildItemID = 0 and PrevItemID != 0)
return "Child"
else if (ParentItemID = 0 and ChildItemID = 0 and PrevItemID != 0)
return "SingleChild"
return 1
}