Jump to content

TreeView Help


DougH
 Share

Recommended Posts

I have a question regarding the TreeView control in version 3. I have written an app that is to create a specific directory structure in My Documents based on the customers name. The first thing I do is check to see if the parent directory already exists. If it does, I list the parent directory and the sub-directories along with the specific structure I want the directory tree to have. I have included the CheckBox option in the tree control, so each folder has a checkbox next to it.

What I would like to do, any directory/folder that already exists I would like to have a check in the checkbox. I have found that I can have the parent directory checked, none checked or all checked. I have not found a way to check individual sub-folders. Is this possible?

If this is not possible, can each folder be displayed with a different font color? This is one of my first attampts at using V3.

Thanks in advance for the help. :)

$DirLst = ("Accounting,Contract,Corrospondance,General Documentation,MealTracter,Menus,Policies and Procedures,Weight Monitor,Work Reports")

$DirArray = Stringsplit($DirLst, ",")

GUICreate("Create Customer Directory", 550, 350)

GUISetState (@SW_Show)

$Tree = GUICtrlCreateTreeView ( 250, 50 ,250, 200, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $TVS_TRACKSELECT), $WS_EX_CLIENTEDGE)

GUICtrlSetState($Level, $GUI_EXPAND)

$Facility = GUICtrlCreateInput ( "", 250, 20, 215, 20)

GUICtrlSetState ( $Facility, $GUI_Show )

GUICtrlSetState ($Facility, $GUI_FOCUS)

GUICtrlCreateLabel("Please Enter the Facilities Short Name:", 50, 20, 200,20,'')

$btn = GUICtrlCreateButton ("Create", 280, 295, 60, 30)

$btn1 = GUICtrlCreateButton ("Cancel", 200, 295, 60, 30)

$btnGo = GUICtrlCreateButton ("Go", 477,20, 20,20)

While 1

$Msg = GUIGetMsg()

Select

Case $Msg = $GUI_EVENT_CLOSE

Exit

Case $Msg = $Facility

$Name = GUICtrlRead ($Facility)

CheckDir($Name)

Case $Msg = $Dir1

$Chk1 = GUICtrlRead($Dir1)

;CheckData($Select)

Case $Msg = $Dir2

$Chk2 = GUICtrlRead($Dir2)

;CheckData($Select)

Case $Msg = $Dir3

$Chk3 = GUICtrlRead($dir33)

;CheckData($Select)

Case $Msg = $btn

CreateDir()

Case $Msg = $BtnGo

CheckDir($Name)

Case $Msg = $btn1

Exit

EndSelect

Wend

Func CheckDir($FName)

If FileExists (@MyDocumentsDir & "\" & $FName) Then

$FileLst = _FileListToArray(@MyDocumentsDir & "\" & $FName, "*", "2")

If $FileLst[0] > $DirArray[0] Then

$Cnt1 = $FileLst[0]

Else

$Cnt1 = $DirArray[0]

Endif

If @Error = 1 Then

MsgBox (4, "Error Message", "Error " & @Error & " - Path not found or invalid. Do you want to Create this Directory?")

MsgBox(0, "Message 1 = ", $Msg1)

Elseif @Error = 2 Then

MsgBox (0, "Error Message", @Error & " - Invalid File Descriptor")

Elseif @Error = 3 Then

MsgBox (0, "Error Message", @Error & " - Invalid aurgument")

Elseif @Error = 4 Then

MsgBox (4, "Error ", @Error & " - Path not found or invalid. Do you want to Create this Directory?")

MsgBox(0, "Message 1 = ", $Msg1)

Else

$Level = GUICtrlCreateTreeViewitem(@MyDocumentsDir, $tree)

For $Cnt = 1 to $Cnt1 Step 1

GUICtrlCreateTreeViewitem($FileLst[$Cnt], $Level)

GUICtrlSetState($Level, BitOR($GUI_EXPAND, $GUI_CHECKED))

If $DirArray[0] >= $Cnt and $FileLst[$Cnt] <> $DirArray[$Cnt] then

GUICtrlSetState($Level,$GUI_UNCHECKED)

GUICtrlCreateTreeViewitem($DirArray[$Cnt], $Level)

Endif

Next

GuiCtrlSetState($Level, BitOr($GUI_EXPAND, $GUI_CHECKED))

EndIf

Else

$Level = GUICtrlCreateTreeViewitem(@MyDocumentsDir & "\" & $FName, $tree)

For $D = 1 to $DirArray[0] step 1

GUICtrlCreateTreeViewitem($DirArray[$D], $Level)

Next

GuiCtrlSetState($Level, BitOr($GUI_EXPAND, $GUI_CHECKED))

Endif

EndFunc

Link to comment
Share on other sites

To get help post syntax correct script. Yours has too many compile errors.

Sorry, I did not put in the Include Statements and variables. They are below.

#include <GUIConstants.au3>

#include <GuiCombo.au3>

#Include <GuiTreeView.au3>

#Include <Array.au3>

#include <File.au3>

Local $Facility

Local $DirArray

Local $btn

Local $btn1

Local $BtnGo

Local $Msg

Local $Msg1

Local $D

Local $Dir1

Local $Dir2

Local $Dir3

Local $Name

Local $FName

Local $ret

Local $Tree

Local $FileLst

Local $Cnt

Local $Cnt1

Local $Level

Link to comment
Share on other sites

You can set bold text for treeview item by:

GUICtrlSetState($tv_item, BitOr(GUICtrlGetState($tv_item),$GUI_DEFBUTTON))
Doesn't that bold everything that is put into the treeview?

I want to be able to have items that already exist bolded and items that do not exits, not bolded. Can this be done?

Link to comment
Share on other sites

Doesn't that bold everything that is put into the treeview?

I want to be able to have items that already exist bolded and items that do not exits, not bolded. Can this be done?

Yes. This is for treeview item (and for whole treeview) as I said ($tv_item).

I'm using this in my script.

Edited by Zedna
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...