UTA Posted March 2, 2010 Share Posted March 2, 2010 (edited) Hi everybody, I'm playing around with a treeview object. But the items in the treeview seem to start at index 4? And I neither know why nor if they begin always at 4. My Prog: expandcollapse popup#Region Includes #include <GUIConstantsEx.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #Include <GuiTreeView.au3> #EndRegion Includes #Region Definitions $ExeFullPath = @ScriptDir & "\" & StringRegExpReplace(@ScriptFullPath, "^.*\\|\..*$", "") & ".exe" $INIFullPath = @ScriptDir & "\" & StringRegExpReplace(@ScriptFullPath, "^.*\\|\..*$", "") & ".ini" Dim $SectionHandles[1] Dim $ItemHandles[1] #EndRegion Definitions #Region GUI $Main = GUICreate("Treeview", 201, 461, 0, 0, BitOR($WS_SIZEBOX,$WS_THICKFRAME,$WS_POPUP,$WS_BORDER, $WS_CAPTION)) $TreeView1 = GUICtrlCreateTreeView(0, 0, 200, 460, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_NOSCROLL)) $SectionNames=GetCategories() If $SectionNames[0]>0 then ReDim $SectionHandles[$SectionNames[0]+1] $SectionHandles[0]=$SectionNames[0] For $i=1 To $SectionNames[0] ; create Category $SectionHandles[$i]=GUICtrlCreateTreeViewItem($SectionNames[$i], $TreeView1) ; create Category-Items $ItemNames=GetCategoryItems($SectionNames[$i]) If $ItemNames[0][0]<>-1 then ReDim $ItemHandles[$ItemNames[0][0]+1] $ItemHandles[0]=$ItemNames[0][0] For $j=1 To $ItemNames[0][0] $ItemHandles[$j]=GUICtrlCreateTreeViewItem($ItemNames[$j][0], $SectionHandles[$i]) Next EndIf Next EndIf GUISetState(@SW_SHOW) #EndRegion GUI #Region GUI-MessageLoop While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE SaveIt() Exit EndSwitch WEnd #EndRegion GUI-MessageLoop #Region Functions Func GetCategories() local $SectionArray[1] If FileExists($INIFullPath) Then $SectionArray=IniReadSectionNames($INIFullPath) ; delete Options-Section (not necessary) local $Options=_ArraySearch($SectionArray, "OPTIONS") If $Options>0 then _ArrayDelete($SectionArray, $Options) If IsArray($SectionArray) Then $SectionArray[0]-=1 Else local $SectionArray[1] $SectionArray[0]=-1 EndIf Else ReDim $SectionArray[1] $SectionArray[0]=-1 EndIf Return $SectionArray EndFunc Func GetCategoryItems($CategoryName) local $ItemArray[1][1] $ItemArray=IniReadSection($INIFullPath, $CategoryName) If @error=1 then $ItemArray[0][0]=-1 Return $ItemArray EndFunc Func SaveIt() ConsoleWrite("Treeview contains " & _GUICtrlTreeView_GetCount($TreeView1) & " elements" & @CRLF) If _GUICtrlTreeView_GetCount($TreeView1)>0 Then ConsoleWrite("Index-First-Item: " & _GUICtrlTreeView_Index($TreeView1, _GUICtrlTreeView_GetFirstItem($TreeView1)) & @CRLF) For $i=0 To 15 ConsoleWrite($i & "/" & _GUICtrlTreeView_GetItemHandle($TreeView1, $i) & ": " & _GUICtrlTreeView_GetText($TreeView1, _GUICtrlTreeView_GetItemHandle($TreeView1, $i)) & @CRLF) Next EndIf EndFunc #EndRegion Functions There should be a .ini-file with the same name as the script-name (e.g. "test.au3" <=> "test.ini") and look similar to this: [OPTIONS] Option1=99 [General] About=1 [DISPLAY] Resolution=2 Other=3 [Test] what=4 Why are the items beginning at index 4 (see the console after closing) ??? UTA Edited March 2, 2010 by UTA Link to comment Share on other sites More sharing options...
Beege Posted March 2, 2010 Share Posted March 2, 2010 Its how you wrote your code. Take a look at this and Notice the consolewrites. I added some to see what your control ids where being set as. #Region GUI $Main = GUICreate("Treeview", 201, 461, 0, 0, BitOR($WS_SIZEBOX,$WS_THICKFRAME,$WS_POPUP,$WS_BORDER, $WS_CAPTION)) $TreeView1 = GUICtrlCreateTreeView(0, 0, 200, 460, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_NOSCROLL)) $SectionNames=GetCategories() If $SectionNames[0]>0 then ReDim $SectionHandles[$SectionNames[0]+1] $SectionHandles[0]=$SectionNames[0] For $i=1 To $SectionNames[0] ; create Category $SectionHandles[$i]=GUICtrlCreateTreeViewItem($SectionNames[$i], $TreeView1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SectionHandles[$i] = ' & $SectionHandles[$i] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console ; create Category-Items $ItemNames=GetCategoryItems($SectionNames[$i]) If $ItemNames[0][0]<>-1 then ReDim $ItemHandles[$ItemNames[0][0]+1] $ItemHandles[0]=$ItemNames[0][0] For $j=1 To $ItemNames[0][0] $ItemHandles[$j]=GUICtrlCreateTreeViewItem($ItemNames[$j][0], $SectionHandles[$i]) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ItemHandles[$j] = ' & $ItemHandles[$j] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console Next EndIf Next EndIf GUISetState(@SW_SHOW) #EndRegion GUI Output shows: >Error code: 0 @@ Debug(35) : $SectionHandles[$i] = 4 >Error code: 0 @@ Debug(44) : $ItemHandles[$j] = 5 >Error code: 0 @@ Debug(35) : $SectionHandles[$i] = 6 >Error code: 0 @@ Debug(44) : $ItemHandles[$j] = 7 >Error code: 0 @@ Debug(44) : $ItemHandles[$j] = 8 >Error code: 0 @@ Debug(35) : $SectionHandles[$i] = 9 >Error code: 0 @@ Debug(44) : $ItemHandles[$j] = 10 Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
UTA Posted March 2, 2010 Author Share Posted March 2, 2010 (edited) Its how you wrote your code. Take a look at this and Notice the consolewrites. I added some to see what your control ids where being set as. I'm not sure if I understand. You mean it's self-induced??? I still can't get it... All I understand is that the first Section ($Section[1]) has the handle/control-ID "4". But I would expect that the item-index (NOT the handle/control-ID) depends on the position in the treeview. Because the position of an item in a treeview could change for instance while the handle should stay always the same, right? UTA Edited March 2, 2010 by UTA Link to comment Share on other sites More sharing options...
Beege Posted March 2, 2010 Share Posted March 2, 2010 I'm not sure if I understand. You mean it's self-induced??? I still can't get it... All I understand is that the first Section ($Section[1]) has the handle/control-ID "4". But I would expect that the item-index (NOT the handle/control-ID) depends on the position in the treeview. Because the position of an item in a treeview could change for instance while the handle should stay always the same, right? UTA Sorry I guess I'm a little confused too. Perhaps its got something to do with mixing the UDF treeview functions with the autoit treeview function. I know I have read many times you should only use one or the other. Ill play around and see if the same thing happens.. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Beege Posted March 2, 2010 Share Posted March 2, 2010 (edited) Real Quick, looking at the _GUICtrlTreeView_GetItemHandle() doc, it states that it needs the Item ID, not the item index. And how i'm reading it is that the index only count's for the children item. aka: Resolution = index 1 Display = index 2 what = index 1 Edited March 2, 2010 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator 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