Jump to content
Sign in to follow this  
gcue

treeview update

Recommended Posts

GEOSoft

We will require a bit more info than that. Can you show how you are creating the TreeView? Does it have static and dynamic elements? Are you adding elements dynamically at runtime? What information will change? I use a very large tree where the tree has certain static elements and then Dynamic elements are added at runtime. If there are changes it calls a _RefreshTree() func that deletes all of the dynamic elements and then rebuilds them. The trick to that is to use a Dummy control as the last control in the GUI and another as the last control in the dynamic elements list or at least a count of the dynamic elements so you have something to reference in a For / Next loop.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

what does an INIreload look like?

inireadsectionnames then rebuild the tree? is there an easier way?

Share this post


Link to post
Share on other sites
gcue

We will require a bit more info than that. Can you show how you are creating the TreeView? Does it have static and dynamic elements? Are you adding elements dynamically at runtime? What information will change? I use a very large tree where the tree has certain static elements and then Dynamic elements are added at runtime. If there are changes it calls a _RefreshTree() func that deletes all of the dynamic elements and then rebuilds them. The trick to that is to use a Dummy control as the last control in the GUI and another as the last control in the dynamic elements list or at least a count of the dynamic elements so you have something to reference in a For / Next loop.

here's how i build it (data residing in an INI file) - pretty static to answer ur question (until someone edits it)

$asset_locs = IniReadSectionNames($aINI)
For $x = 1 To $asset_locs[0]
    $asset_loc_suffix = StringRight($asset_locs[$x], 7)
    If $asset_loc_suffix = "_ASSETS" Or $asset_loc_suffix = "TARGETS" Then
        $group = GUICtrlCreateTreeViewItem($asset_locs[$x], $editINI_treeview)
        GUICtrlSetColor(-1, 0x0000C0)
        
        $assets = IniReadSection($aINI, $asset_locs[$x])

        For $y = 1 To $assets[0][0]
            $pc = GUICtrlCreateTreeViewItem($assets[$y][0], $group)
            GUICtrlSetColor(-1, 0x0000C0)
            
            $item_menu = GUICtrlCreateContextMenu($pc)
            $item_edit = GUICtrlCreateMenuItem("Edit", $item_menu)
            GUICtrlSetOnEvent(-1, "INI_Item_Edit_GUI")
            
            
        Next
    EndIf
Next

Share this post


Link to post
Share on other sites
GEOSoft

Put that in a Function called _TreeRefresh() or what ever Then use something similar to below.

$sIni = FileRead($aIni)
$Frm_Main = GUICreate("My Test Form")
$tree = GUICtrlCreateTreeView("", 10, 10, 100, 100)
$hStart = GUICtrlCreateDummy()
_TreeRefresh()
$hEnd = GUICtrlCreateDummy()
GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
            Exit
        Case Else
    EndSwitch
    If FileRead($aIni) <> $sIni Then
         For $i = $hStart+1 To $hEnd
             GUICtrlDelete($i)
         Next
         _TreeRefresh()
        $hEnd = GUICtrlCreateDummy()
        $sIni = FileRead($aIni)
    EndIf
WEnd

Func _TreeRefresh()
$asset_locs = IniReadSectionNames($aINI)
For $x = 1 To $asset_locs[0]
    $asset_loc_suffix = StringRight($asset_locs[$x], 7)
    If $asset_loc_suffix = "_ASSETS" Or $asset_loc_suffix = "TARGETS" Then
        $group = GUICtrlCreateTreeViewItem($asset_locs[$x], $editINI_treeview)
        GUICtrlSetColor(-1, 0x0000C0)
        
        $assets = IniReadSection($aINI, $asset_locs[$x])

        For $y = 1 To $assets[0][0]
            $pc = GUICtrlCreateTreeViewItem($assets[$y][0], $group)
            GUICtrlSetColor(-1, 0x0000C0)
            
            $item_menu = GUICtrlCreateContextMenu($pc)
            $item_edit = GUICtrlCreateMenuItem("Edit", $item_menu)
            GUICtrlSetOnEvent(-1, "INI_Item_Edit_GUI")
            
            
        Next
    EndIf
Next
EndFunc

Without digging through one of my apps to double check, this should be pretty close. You might have to tweak it a bit but the important part is where you declare $hStart and $hEnd. They must be after all the other controls. You could also put them inside the function to make it simple but remember to declare them as Global variables. I didn't do that because I was refreshing either of 2 TreeViews with the same functions so I had 2 start and end points.

Edit: I should have added the fact that there are also some functions in GuiTreeView.au3 that you can use. You will find them in the help file under User Defined Functions>>TreeView Management. I just found it easier in my case to delete them all and then rebuild the tree.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

hehe wow.. looks funny when its updating - but it works =D

thanks =)

Edited by gcue

Share this post


Link to post
Share on other sites
GEOSoft

hehe wow.. looks funny when its updating - but it works =D

thanks =)

NP. If the treeView is collapsed you won't have that funny look. BTW: With mine I had some static branches that were not changed so I was only refreshing the subs.

EDIT: A quick tweak for that funny look is to hide the TreeView control during the refresh.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

have u seen sandin's utility?

http://www.autoitscript.com/forum/index.ph...c=85992&hl=

its awesome.. not sure how he does his refreshing

sandin always does a nice job. There are a few ways to handle your situation. I jusy gave you the quick and dirty one. The rest is up to you.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
gcue

thanks again =)

Share this post


Link to post
Share on other sites
GEOSoft

YW

The good part is that it works as requested.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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  

×