Jump to content

Dynamic GUI Tree and Updating Realtime


Recommended Posts

I am using the GUI Tree to create a listing from a Database which is constantly being modified by user input and need the Tree to update with these changes.

I have found simply destroying the Tree and rebuilding it with the new Database info works however I am sure there is an easier way to achieve this?

Also there are multiple Parents with the same name which are not grouping the contents together, instead it is creating their own Tree Items (see below).

Any assistance would be greatly appreciated.

#include <SQLite.au3>
#include <SQLite.dll.au3>
#include <GUIConstantsEx.au3>
#include <GUITreeView.au3>

Opt("MustDeclareVars", 1)

Dim $hDb, $hMsg, $hTree, $hQuery, $hRow, $iUrl, $bUrl, $iEmail, $bEmail

_SQLite_Startup()
$hDb = _SQLite_Open()
_SQLite_Exec($hDb, "CREATE TABLE example (Parent, Child);")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Website', 'http://www.a.com');")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Website', 'http://www.b.com');")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Website', 'http://www.c.com');")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Email', 'a@emailaddress.com');")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Email', 'b@emailaddress.com');")
_SQLite_Exec($hDb, "INSERT INTO example VALUES ('Email', 'c@emailaddress.com');")

GUICreate("", 400, 300)

    _iTree()
    
    ;Add Website
    $iUrl = GUICtrlCreateInput("<website>", 200, 10, 160, 20)
    $bUrl = GUICtrlCreateButton("Add", 365, 10, 30, 20)
    
    ;Add Email
    $iEmail = GUICtrlCreateInput("<email>", 200, 50, 160, 20)
    $bEmail = GUICtrlCreateButton("Add", 365, 50, 30, 20)
    
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Select
        Case $hMsg = $bUrl
            _bUrl()
            _GUICtrlTreeView_Destroy($hTree)
            _iTree()
            
        Case $hMsg = $bEmail
            _bEmail()
            _GUICtrlTreeView_Destroy($hTree)
            _iTree()
            
        Case $hMsg = $GUI_EVENT_CLOSE
            _SQLite_Shutdown()
            Exit
    EndSelect
WEnd

Func _bUrl()
    Local $rUrl = GUICtrlRead($iUrl)
    If $rUrl = "" Then Return
    
    _SQLite_Exec($hDb, "INSERT INTO example VALUES ('Website', '" & $rUrl & "');")
EndFunc ;BUTTON: Add Website
    
Func _bEmail()
    Local $rEmail = GUICtrlRead($iEmail)
    If $rEmail = "" Then Return
    
    _SQLite_Exec($hDb, "INSERT INTO example VALUES ('Email', '" & $rEmail & "');")
    
EndFunc ;BUTTON: Add Email

Func _iTree()
    $hTree = GUICtrlCreateTreeView(10,10, 180, 280)
    
    _SQLite_Query($hDb, "SELECT * FROM example;", $hQuery)
    
    While _SQLite_FetchData($hQuery, $hRow)  = $SQLITE_OK
        GUICtrlCreateTreeViewItem($hRow[0], $hTree)
        GUICtrlCreateTreeViewItem($hRow[1], -1)
    WEnd
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...