Scamp Posted June 11, 2009 Share Posted June 11, 2009 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 Link to comment Share on other sites More sharing options...
Zedna Posted June 11, 2009 Share Posted June 11, 2009 (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 June 11, 2009 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 11, 2009 Moderators Share Posted June 11, 2009 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:expandcollapse popup#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 ;==>_MainM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Scamp Posted June 11, 2009 Author Share Posted June 11, 2009 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:expandcollapse popup#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 Link to comment Share on other sites More sharing options...
Scamp Posted June 11, 2009 Author Share Posted June 11, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now