Sign in to follow this  
Followers 0
Scamp

GUICtrlCreateTreeViewItem

5 posts in this topic

Hello,

I am trying to create an GUICtrlCreateTreeViewItem control that will firstly read an ini files section headings then it will read the contents of the section into the apporiate section. My problem is can read the section headings into the GUItree but then when i try and add the contents into the correct section it doesn't update the tree. If i have attached the code i'm using if some can give some pointers where i am going wrong that would be great.

Thanks

Scampi

Code (Sorry can't seem create a code section)

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <TreeViewConstants.au3>

#include <file.au3>

_Main()

Func _Main()

;Declares Varibles

Local $maintree

Dim $aRecords

Dim $CustomerName

GUICreate("MENU", 800, 600)

;Creating Tree View

$maintree = GUICtrlCreateTreeView(150, 10, 600, 500)

;Creating Side Buttons

$okbutton = GUICtrlCreateButton("&OK", 10, 570, 100)

$Closebutton = GUICtrlCreateButton("&Exit", 690, 570, 100)

;Creating GUI Menu

GUISetState(@SW_SHOW)

$var = IniReadSectionNames("c:\Temp\Test.ini")

If @error Then

MsgBox(4096, "", "Error occurred, probably no INI file.")

Else

For $i = 1 To $var[0]

$var1 = IniReadSection("C:\Temp\Test.ini", ($Var[$i]))

If @error Then

MsgBox(4096, "", "Error occurred, probably no INI file.")

Else

For $x = 1 To $var1[0][0]

GUICtrlCreateTreeViewItem(($Var[$i]),$maintree)

GUICtrlCreateTreeViewItem(($Var1[$x][1]),($Var[$i]))

Next

EndIf

Next

EndIf

While 1

$msg = GUIGetMsg()

Select

Case $msg = $okbutton

MsgBox(0, "GUI Event", "You pressed OK!")

Case $msg = $closebutton

exitloop

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

wend

EndFunc

Sample INI Section

Created in c:\temp\test.ini

[Heading1]

Key=Value

[Heading2]

Key=Value

[Heading3]

Key=Value

[Heading4]

Key=Value

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try to replace

GUICtrlCreateTreeViewItem(($Var[$i]),$maintree)
GUICtrlCreateTreeViewItem(($Var1[$x][1]),($Var[$i]))

with

$tmp = GUICtrlCreateTreeViewItem($Var[$i],$maintree)
GUICtrlCreateTreeViewItem($Var1[$x][1],$tmp)
Edited by Zedna

Share this post


Link to post
Share on other sites

Scamp,

First, welcome to the AutoIt forums. A good start - some code to work on and a clear question. I wish some other newcomers would do the same. ;-)

Code tags: - put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here).

Your problem - you must get the ControlID of the treeview children:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <file.au3>
#include <Array.au3>

_Main()

Func _Main()
;Declares Varibles
    Local $maintree
    Dim $aRecords
    Dim $CustomerName

    GUICreate("MENU", 800, 600)
;Creating Tree View
    $maintree = GUICtrlCreateTreeView(150, 10, 600, 500)

;Creating Side Buttons
    $okbutton = GUICtrlCreateButton("&OK", 10, 570, 100)
    $Closebutton = GUICtrlCreateButton("&Exit", 690, 570, 100)

;Creating GUI Menu
    GUISetState(@SW_SHOW)

    $var = IniReadSectionNames(@ScriptDir & "\Test.ini")

    If @error Then
        MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
        For $i = 1 To $var[0]
            $var1 = IniReadSection(@ScriptDir & "\Test.ini", ($var[$i]))

            If @error Then
                MsgBox(4096, "", "Error occurred, probably no INI file.")
            Else
                $treechild = GUICtrlCreateTreeViewItem(($var[$i]), $maintree); <<<<<<<<<
                For $x = 1 To $var1[0][0]
                    GUICtrlCreateTreeViewItem(($var1[$x][1]), $treechild)  ; <<<<<<<<<<
                Next
            EndIf
        Next
    EndIf

    While 1
        $msg = GUIGetMsg()
        Select

            Case $msg = $okbutton
                MsgBox(0, "GUI Event", "You pressed OK!")

            Case $msg = $Closebutton
                ExitLoop

            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

        EndSelect

    WEnd

EndFunc  ;==>_Main

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Scamp,

First, welcome to the AutoIt forums. A good start - some code to work on and a clear question. I wish some other newcomers would do the same. ;-)

Code tags: - put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here).

Your problem - you must get the ControlID of the treeview children:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <file.au3>
#include <Array.au3>

_Main()

Func _Main()
;Declares Varibles
    Local $maintree
    Dim $aRecords
    Dim $CustomerName

    GUICreate("MENU", 800, 600)
;Creating Tree View
    $maintree = GUICtrlCreateTreeView(150, 10, 600, 500)

;Creating Side Buttons
    $okbutton = GUICtrlCreateButton("&OK", 10, 570, 100)
    $Closebutton = GUICtrlCreateButton("&Exit", 690, 570, 100)

;Creating GUI Menu
    GUISetState(@SW_SHOW)

    $var = IniReadSectionNames(@ScriptDir & "\Test.ini")

    If @error Then
        MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
        For $i = 1 To $var[0]
            $var1 = IniReadSection(@ScriptDir & "\Test.ini", ($var[$i]))

            If @error Then
                MsgBox(4096, "", "Error occurred, probably no INI file.")
            Else
                $treechild = GUICtrlCreateTreeViewItem(($var[$i]), $maintree); <<<<<<<<<
                For $x = 1 To $var1[0][0]
                    GUICtrlCreateTreeViewItem(($var1[$x][1]), $treechild) ; <<<<<<<<<<
                Next
            EndIf
        Next
    EndIf

    While 1
        $msg = GUIGetMsg()
        Select

            Case $msg = $okbutton
                MsgBox(0, "GUI Event", "You pressed OK!")

            Case $msg = $Closebutton
                ExitLoop

            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop

        EndSelect

    WEnd

EndFunc ;==>_Main

M23

Share this post


Link to post
Share on other sites

Zedna & Melba23 thank you both for your speedy reply's. I didn't reliase that you could set a varable to be a item as well. Always a good thing when trying to learn a new programming language. :-)

Thanks again

Scamp

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  
Followers 0