Clark Posted August 27, 2013 Share Posted August 27, 2013 Hi there I am getting a strange issue occuring with treeview. The below code creates a three level treeview. Each top level item has subitems, so all the top level items should have a "+" before them, allowing them to be expanded. However, what is happening is that the last top level item is not showing a plus sign, until it is clicked once - then the plus sign appears. Does anyone have an idea as to why this is happening? Func _Populate_System_Treeview() local $iNumberSystems,$iCount,$iFields,$tempRecord,$tv1,$tv2,$tv3 $sSQL="Select * from tbl_systems;" If Not _EzMYSql_Query($sSQL) Then MsgBox(0, "Query Error", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg()) EndIf $iNumberSystems = _EzMySql_Rows() ; Number of systems (rows) in the table global $tvi[$iNumberSystems][5] for $iCount = 0 to $iNumberSystems-1 ; for each row in the table $tempRecord = _EzMySql_FetchData() ; Read the row into a temporary var for $iFields = 0 to 3 $tvi[$iCount][$iFields]=$tempRecord[$iFields] ; Fourth field reserved for pointer to treeviewbox items Next Next _ArraySort($tvi,0,0,0,0) for $iCount = 0 to $iNumberSystems-1 Switch $tvi[$iCount][2] ; SYS_level field Case 1 ; Top level $tv1=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $treeview) ; Display the item $tvi[$iCount][4]=$tv1 Case 2 ; Second level $tv2=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv1) $tvi[$iCount][4]=$tv2 Case 3 ; THird level $tv3=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv2) $tvi[$iCount][4]=$tv3 Case Else ; Should never happen ; msgbox(0,"Warning","Undefined system level detected") EndSwitch Next EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2013 Moderators Share Posted August 27, 2013 Clark,Unless you provide some runnable code which shows the problem, you are unlikely to get any useful responses. At present you are expecting us to write our own code to create a GUI to hold your treeview, create a SQL databasde to query with no idea what the resultant array format, and then add your function to even see the problem. Would you be prepared to do all that? You post a runnable script which illustrates the problem and I will be happy to look into what might be happening. But at the moment there is absolutely no chance. M23 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...
Clark Posted August 30, 2013 Author Share Posted August 30, 2013 OK, fair call, although I was hoping that someone could just spot the problem in the code without necessarily having to run it. Anway, I have added some code around it to illustrate the issue - although now you don't need to click the last line of the treeview to make the final + appear - you just have to hover over it. expandcollapse popup#include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> $Form1_1 = GUICreate("Request for Change", 977, 917, 467, 37) $TreeView = GUICtrlCreateTreeView(617, 190, 336, 300,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) _Populate_System_Treeview() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Populate_System_Treeview() ; Due to the retardness of the mySQL udf this has to be build as an in-memory array rather than straight to screen local $iNumberSystems=27,$iCount,$iFields,$tempRecord[5],$tv1,$tv2,$tv3 global $tvi[$iNumberSystems][5] for $iCount = 0 to $iNumberSystems-1 ; for each row in the table $tempRecord = _Emulate_EzMySql_FetchData($iCount) ; Read the row into a temporary var for $iFields = 0 to 3 $tvi[$iCount][$iFields]=$tempRecord[$iFields] ; Fourth field reserved for pointer to treeviewbox items Next Next _ArraySort($tvi,0,0,0,0) for $iCount = 0 to $iNumberSystems-1 Switch $tvi[$iCount][2] ; SYS_level field Case 1 ; Top level $tv1=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $treeview) ; Display the item $tvi[$iCount][4]=$tv1 Case 2 ; Second level $tv2=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv1) $tvi[$iCount][4]=$tv2 Case 3 ; THird level $tv3=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv2) $tvi[$iCount][4]=$tv3 Case Else ; Should never happen ; msgbox(0,"Warning","Undefined system level detected") EndSwitch Next EndFunc Func _Emulate_EzMySql_FetchData($idx) local $retstring[5],$lCntr local $tvi[28][3] = [ _ [100,"SAP ERP", 1], _ [110,"(CRM) Customer Relationship Management", 1], _ [111,"Interaction Centre", 2], _ [112,"Activity and CRM Ticket Mgmt", 3], _ [113,"Grants CRM Mgmt", 3], _ [114,"Electronic Document Records Mgmt System",3], _ [120,"(ECC) ERP Central Component", 3], _ [121,"Finance Controlling and Funds Mgmt", 2], _ [122,"Human Capital Mgmt", 3], _ [123,"Materials Mgmt", 3], _ [124,"Treasury Mgmt System", 3], _ [130,"Enterprise Portal", 3], _ [140,"Business Intelligence/Warehouse", 2], _ [150,"XI / PI Interfaces", 2], _ [160,"Solution Manager", 2], _ [200,"GOS", 2], _ [210,"Lotos", 1], _ [220,"BOS", 2], _ [230,"Terminal", 2], _ [300,"Corporate IT", 2], _ [310,"Email", 1], _ [320,"Intranet", 2], _ [400,"Digital Point of Presence", 2], _ [410,"Play Online", 1], _ [420,"Retail Link", 2], _ [430,"Corporate Website General", 2], _ [440,"Corporate Website Grants", 2]] for $lCntr = 0 to 2 $retstring[$lCntr]=$tvi[$idx][$lCntr] Next return ($retstring) endfunc Link to comment Share on other sites More sharing options...
NewPlaza Posted August 30, 2013 Share Posted August 30, 2013 Try placing this GUISetState(@SW_SHOW) after this _Populate_System_Treeview() Link to comment Share on other sites More sharing options...
BrewManNH Posted August 30, 2013 Share Posted August 30, 2013 Good call NewPlaza, that seems to have fixed it on my system at least. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Clark Posted August 30, 2013 Author Share Posted August 30, 2013 Thanks for that good try. I tried that previously, but unfortunately it doesn't fix it on my system. Not on the "real" program nor the "test" program I have included. In fact, on the test program it makes it emulate the real program, in that the + does not appear until I click the last line. Very strange. Link to comment Share on other sites More sharing options...
BrewManNH Posted August 30, 2013 Share Posted August 30, 2013 I tried your example script and I was seeing the problem before moving the GUISetState function below the line that creates the treeview. After moving it, the problem went away, at least on the 2 different computers I ran it on. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
BrewManNH Posted August 30, 2013 Share Posted August 30, 2013 One trick you could use is adding this line after your return from creating all of the treeview items. GUICtrlDelete(GUICtrlCreateTreeViewItem("",$TreeView)) This adds an additional root level treeview item and immediately deletes it, which makes the bottom treeview item have the "+" sign show up every time. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
FireFox Posted August 30, 2013 Share Posted August 30, 2013 (edited) It works here (Windows XP), so it may be a missing control redraw call (in Windows 7?)This should fix the issue (although I can't test it to adapt the redraw message)._WinAPI_RedrawWindow($Form1_1, 0, $hTreeeView, $RDW_ERASENOW)Br, FireFox. Edited August 30, 2013 by FireFox Link to comment Share on other sites More sharing options...
Solution Clark Posted September 4, 2013 Author Solution Share Posted September 4, 2013 Brewman's method works a treat. Thanks. Firefox I didn't try your method but thanks for that. And thanks to all for the good trys. Link to comment Share on other sites More sharing options...
kylomas Posted September 20, 2013 Share Posted September 20, 2013 (edited) @all - Follow-up I recently had exactly the same problem. Adding a "_guictrltreeview_beginupdate", "_guictrltreeview_endupdate" pair fixed it... expandcollapse popup#include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> #include <GuiTreeView.au3> ; <---- added for _guictrltreeview* functions $Form1_1 = GUICreate("Request for Change", 977, 917, 467, 37) $TreeView = GUICtrlCreateTreeView(617, 190, 336, 300,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) GUISetState(@SW_SHOW) _Populate_System_Treeview() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Populate_System_Treeview() ; _GUICtrlTreeView_BeginUpdate($treeview) ; <----- added ; ; Due to the retardness of the mySQL udf this has to be build as an in-memory array rather than straight to screen local $iNumberSystems=27,$iCount,$iFields,$tempRecord[5],$tv1,$tv2,$tv3 global $tvi[$iNumberSystems][5] for $iCount = 0 to $iNumberSystems-1 ; for each row in the table $tempRecord = _Emulate_EzMySql_FetchData($iCount) ; Read the row into a temporary var for $iFields = 0 to 3 $tvi[$iCount][$iFields]=$tempRecord[$iFields] ; Fourth field reserved for pointer to treeviewbox items Next Next _ArraySort($tvi,0,0,0,0) for $iCount = 0 to $iNumberSystems-1 Switch $tvi[$iCount][2] ; SYS_level field Case 1 ; Top level $tv1=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $treeview) ; Display the item $tvi[$iCount][4]=$tv1 Case 2 ; Second level $tv2=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv1) $tvi[$iCount][4]=$tv2 Case 3 ; THird level $tv3=GUICtrlCreateTreeViewItem($tvi[$iCount][1], $tv2) $tvi[$iCount][4]=$tv3 Case Else ; Should never happen ; msgbox(0,"Warning","Undefined system level detected") EndSwitch Next ; _GUICtrlTreeView_endUpdate($treeview) ; <--- added ; EndFunc Func _Emulate_EzMySql_FetchData($idx) local $retstring[5],$lCntr local $tvi[28][3] = [ _ [100,"SAP ERP", 1], _ [110,"(CRM) Customer Relationship Management", 1], _ [111,"Interaction Centre", 2], _ [112,"Activity and CRM Ticket Mgmt", 3], _ [113,"Grants CRM Mgmt", 3], _ [114,"Electronic Document Records Mgmt System",3], _ [120,"(ECC) ERP Central Component", 3], _ [121,"Finance Controlling and Funds Mgmt", 2], _ [122,"Human Capital Mgmt", 3], _ [123,"Materials Mgmt", 3], _ [124,"Treasury Mgmt System", 3], _ [130,"Enterprise Portal", 3], _ [140,"Business Intelligence/Warehouse", 2], _ [150,"XI / PI Interfaces", 2], _ [160,"Solution Manager", 2], _ [200,"GOS", 2], _ [210,"Lotos", 1], _ [220,"BOS", 2], _ [230,"Terminal", 2], _ [300,"Corporate IT", 2], _ [310,"Email", 1], _ [320,"Intranet", 2], _ [400,"Digital Point of Presence", 2], _ [410,"Play Online", 1], _ [420,"Retail Link", 2], _ [430,"Corporate Website General", 2], _ [440,"Corporate Website Grants", 2]] for $lCntr = 0 to 2 $retstring[$lCntr]=$tvi[$idx][$lCntr] Next return ($retstring) endfunc kylomas edit: @Clark - Your array to populate the treeview requires strict order of items in the array. See thread for another way to do this using an array. Edited September 20, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
FireFox Posted September 20, 2013 Share Posted September 20, 2013 Maybe because the EndUpdate function redraws the treeview. 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