matwachich Posted May 21, 2019 Share Posted May 21, 2019 (edited) Hi guys! Backgroud: I have a TreeView that contains Dates as parent items, and in each day, events (child items). I'm trying to create a function that will either add an event (and his date parent), or update an event's sub-item if it already exists (searched by lParam). But I have a strage behaviour when searching the treeview items (_GetFirstChild, _GetNextChild). See the code : expandcollapse popup#include <GuiTreeView.au3> $hGUI = GUICreate("Test", 400, 300) $hTV = GUICtrlCreateTreeView(8, 8, 384, 284) GUISetState() __guiTv_addOrUpdateItem($hTV, "Date 1", "Item 1", 10) __guiTv_addOrUpdateItem($hTV, "Date 1", "Item 2", 20) __guiTv_addOrUpdateItem($hTV, "Date 1", "Item 3", 30) ; normaly, this should change sub-item 2 text __guiTv_addOrUpdateItem($hTV, "Date 1", "Changed!", 20) While 1 $iMsg = GUIGetMsg() Switch $iMsg Case -3 Exit EndSwitch WEnd Func __guiTv_addOrUpdateItem($hTV, $sMainText, $sSubText, $iParam, $hParentItem = Default) ; find or create parent item If $hParentItem == Default Then $hParentItem = _GUICtrlTreeView_FindItem($hTV, $sMainText) If $hParentItem == 0 Then $hParentItem = _GUICtrlTreeView_InsertItem($hTV, $sMainText, 0, $TVI_SORT) EndIf ConsoleWrite("ParentItem: " & $hParentItem & " (" & _GUICtrlTreeView_GetText($hTV, $hParentItem) & ")" & @CRLF) ; see if there's already a sub-item with $iParam Local $hChild = _GUICtrlTreeView_GetFirstChild($hTV, $hParentItem) While $hChild ConsoleWrite("Check child: " & $hChild & " (" & _GUICtrlTreeView_GetText($hTV, $hChild) & ")" & @CRLF) If _GUICtrlTreeView_GetItemParam($hTV, $hChild) == $iParam Then ; if found: change it's text and return _GUICtrlTreeView_SetText($hTV, $hChild, $sSubText) Return $hChild EndIf $hChild = _GUICtrlTreeView_GetNextChild($hTV, $hChild) WEnd ; create new sub-item $hChild = _GUICtrlTreeView_AddChild($hTV, $hParentItem, $sSubText) _GUICtrlTreeView_SetItemParam($hTV, $hChild, $iParam) Return $hChild EndFunc 2 problems : - First: there is a totally inconsistent behaviour when calling the _GetFirstChild function: sometimes it returns good, sometimes not! (run the script many times and see the console output) - Second: the _GetItemParam function doesn't work! Always returning 0 I'll be very thankfull for any help Edit: Problem solved (I think): _GuiCtrlTreeView_ functions doesn't work very well with control IDs. I did this and it worked $hTV = GUICtrlGetHandle(GUICtrlCreateTreeView(8, 8, 384, 284)) $hTV = GUICtrlGetHandle(GUICtrlCreateTreeView(8, 8, 384, 284)) But, why!? Edited May 21, 2019 by matwachich Link to comment Share on other sites More sharing options...
Nine Posted May 22, 2019 Share Posted May 22, 2019 If you look at the remark of _GUICtrlTreeView_SetItemParam, it says : Warning: Do not use this function on items created with GUICtrlCreateTreeViewItem(). But it should also says that it should not be used with tree view created with GUICtrlCreateTreeView because it returns ID instead of handle. The way you solved your issue with GUICtrlGetHandle, it translates ID into handle, so this works fine. Or you could simply use _GUICtrlTreeView_Create that is returning a handle. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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