Jump to content
Sign in to follow this  

TreeView confusion

Recommended Posts


Gui still confuses me :P

With treeview... say I have something like this:

+ Category 1

|_ Item 1

|_ Item 2

|_ Item 3

I know when the user presses the + it folds/expands the Category 1. Is there some way that the + can be a control with its own event?

Basically, I have hundreds of "Category"s each with some unknown number of "Item"s and it takes too long to generate the entire treeview with them all. What I want to achieve is that WHEN the user presses +, it runs a function that determines what should be in there.

At first glance, this doesn't seem possible because the + doesn't even exist unless the "Category" has at least one "item" in it. I suppose I can get around that with a dummy item that gets deleted after the + is pressed... hmm.

But I don't even know how I would go about calling the function with the + press.

Any ideas?



Share this post

Link to post
Share on other sites

This is an interesting problem. I would also like to see how it can be done.

Share this post

Link to post
Share on other sites

Here an example from ..... (Valuater if I remember right)

Execute it and it will show you every item you have clicked (also Parents).

HTH, Reinhard

#include <GUIConstants.au3>
Dim $curlevel = 1
Dim $aTree = StringSplit(FileRead("Tree.dat", FileGetSize("Tree.dat")), @LF)

$hTree = GUICtrlCreateTreeView(5, 5, 300, 200)

Dim $ahDepth[100]
$ahDepth[0] = $hTree

For $i = 1 to $aTree[0]
    $line = StringStripCR($aTree[$i])
    $markpos = StringInStr($line, "#")
    If $markpos <> $curlevel Then $curlevel = $markpos
    $ahDepth[$markpos] = GUICtrlCreateTreeViewItem(StringMid($line, $markpos+1), $ahDepth[$markpos-1])


While 1
    $nMsg = GUIGetMsg()
    if $nMsg > $ahDepth[$markpos] - Ubound($aTree) + 1 then 
       msgBox(0,"",$aTree[$nMsg-($ahDepth[$markpos] - Ubound($aTree)+1)])
    If $nMsg = -3 Then Exit

Here the Tree.dat file for the TV example, which must be in the script dir.

#Level 1.1
 #Level 2.1
 #Level 2.2
 #Level 2.3
  #Level 3.1
   #Level 4.1
  #Level 3.2
 #Level 2.4
  #Level 3.3
#Level 1.2
 #Level 2.5
 #Level 2.6
Edited by ReFran

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.