[function] CreateTreeView
Creates TreeView from a string in which each item is placed in new line and hierarchy is defined by Tab character on the left. Item options can be added after one or more Tab characters after item name. This function is public domain.
Function
CreateTreeView(TreeViewDefinitionString) { ; by Learning one IDs := {} Loop, parse, TreeViewDefinitionString, `n, `r { if A_LoopField is space continue Item := RTrim(A_LoopField, A_Space A_Tab), Item := LTrim(Item, A_Space), Level := 0 While (SubStr(Item,1,1) = A_Tab) Level += 1, Item := SubStr(Item, 2) RegExMatch(Item, "([^`t]*)([`t]*)([^`t]*)", match) ; match1 = ItemName, match3 = Options if (Level=0) IDs["Level0"] := TV_Add(match1, 0, match3) else IDs["Level" Level] := TV_Add(match1, IDs["Level" Level-1], match3) } } ; http://www.autohotkey.com/board/topic/92863-function-createtreeview/Example 1 - basic
TvDefinition= ( File New Open Save Save as... Exit Edit Undo Cut Copy Paste Delete View Full screen Zoom 100 200 Help ) Gui, Add, TreeView, h300 CreateTreeView(TvDefinition) Gui, Show return GuiClose: ExitAppExample 2 - items with options
TvDefinition= ( File bold New Open bold Save Save as... Exit Edit Undo Cut Copy Paste Delete View Expand Full screen Select Zoom 100 200 Help ) Gui, Add, TreeView, h300 CreateTreeView(TvDefinition) Gui, Show return GuiClose: ExitAppSee also: [function] CreateMenu