Jump to content

Need help with treeview


 Share

Recommended Posts

Hi all,

If you run the code it will search for ini's. But how to update the tabitem 'Algemeen' With information thats inside the selected ini. So if I click the + sign from one of the treeview items and then select an item, it will read the information from the ini into the tab 'algemeen. I'll need to make Labels to let the information really appear, but how to read the information from the ini into the tab 'algemeen? thanks!

The Code:

#include <GUIConstants.au3>

GUICreate("My GUI", 780, 400)  ; will create a dialog box that when displayed is centered
$treeview = GUICtrlCreateTreeView(5, 15, 120, 350)
$hdd1 = GUICtrlCreateTreeViewItem("Groepen", $treeview)
GUICtrlSetColor(-1, 0x0000C0)
$search = FileFindFirstFile("Groepen\*.ini")  

; Check if the search was successful
If $search = -1 Then
 MsgBox(0, "Error", "Geen groepen gevonden!")
 Exit
EndIf

While 1
 $file = FileFindNextFile($search) 
 If @error Then ExitLoop
 $replace = StringReplace($file, ".ini", "")
 GUICtrlCreateTreeViewItem($replace, $hdd1)
WEnd

; Close the search handle
FileClose($search)

;-------------------------------------------------

$hdd2 = GUICtrlCreateTreeViewItem("Gebruikers", $treeview)
GUICtrlSetColor(-1, 0x0000C0)

$search2 = FileFindFirstFile("Users\*.ini")  

; Check if the search was successful
If $search2 = -1 Then
 MsgBox(0, "Error", "Geen gebruikers gevonden!")
 Exit
EndIf

While 1
 $file2 = FileFindNextFile($search2) 
 If @error Then ExitLoop
 $replace2 = StringReplace($file2, ".ini", "")
 GUICtrlCreateTreeViewItem($replace2, $hdd2)
WEnd

; Close the search handle
FileClose($search2)

GUICtrlSetState($hdd1, $GUI_DEFBUTTON)
GUICtrlSetState($hdd2, $GUI_DEFBUTTON)

$tab = GUICtrlCreateTab(140, 5, 630, 380)
GUICtrlCreateTabItem("Algemeen")
GUICtrlCreateLabel("TEKST KOMT HIER", 190, 50)
GUICtrlCreateTabItem("Cijfers")
GUICtrlCreateTabItem("Beoordelingen")

GUISetState (@SW_SHOW)       ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
 $msg = GUIGetMsg()
 
 If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
Link to comment
Share on other sites

Ok, i have a headache from trying to uderstand that, but I think you should try reading the information with IniRead, then just using the returns from that to create new tree items. I'm not sure though cause I don't really completly understand you and it's 4 o' clock in the morning and i just finished my third Rockstar. YAY FOR WORKING ALL NIGHT!

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Link to comment
Share on other sites

OK, I'll try to explain it better. When You run this code, you'l see two treeview Items: Groepen and gebruikers. When you expand one of them, you'll see the found ini's, without their extention. Now I want to be able to click one of the results and then the program will update the information, wich is read from the selected ini, in the tabitem 'algemeen'. Thanks!

Link to comment
Share on other sites

You might want to create a sort of "loading" function, that reads in all the data from the ini files, and stores(returns) an array with all the data in them, and/or adds them to the three view, then you will have to store all the "GUICtrlCreateTreeViewItem" control id's in an array so you can access them later on.

You'll have to look up in the Func funciton, the IniReadSection and IniReadSectionNames functions...

Managing data within a gui is quite tricky if you ask me...

Edited by FreeFry
Link to comment
Share on other sites

Hi,

I know you asked to read the selected ini into a Label, but I did it with a ReadOnly Editbox instead..

This way you can scroll if the ini text is longer then the label.

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

Global $IniPath1 = @ScriptDir & "\Groepen\*.ini", $IniPath2 = @ScriptDir & "\Gebruikers\*.ini"

$Gui = GUICreate("My GUI", 780, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "Event", $Gui)

$TV = GUICtrlCreateTreeView(5, 15, 120, 350)
$TVI1 = GUICtrlCreateTreeViewItem("Groepen", $TV)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
TVLoadIni($TVI1, $IniPath1)
$TVI2 = GUICtrlCreateTreeViewItem("Gebruikers", $TV)
GUICtrlSetColor(-1, 0x0000C0)
GUICtrlSetState(-1, $GUI_DEFBUTTON)
TVLoadIni($TVI2, $IniPath2)
$tab = GUICtrlCreateTab(140, 5, 630, 380)
GUICtrlCreateTabItem("Algemeen")
$Edit1 = GUICtrlCreateEdit("TEKST KOMT HIER", 150, 40, 608, 331, BitOR($WS_VSCROLL, $WS_HSCROLL,$ES_READONLY))
GUICtrlSetBkColor(-1, 0xffffff)
GUICtrlCreateTabItem("Cijfers")
GUICtrlCreateTabItem("Beoordelingen")
GUISetState (@SW_SHOW, $Gui)

While 1
    Sleep(100)
Wend

Func Event()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            Local $FO = FileOpen(@ScriptDir & "\" & _TVGetItemTree($TV, "\") & ".ini", 0)
            If $FO <> -1 Then
                Local $FR = FileRead($FO)
                If Not @error Then GUICtrlSetData($Edit1, $FR)
            EndIf
            FileClose($FO)
    EndSwitch
EndFunc

Func TVLoadIni($tviID, $iPath)
    Local $FFFF, $FFNF, $STR
    $FFFF = FileFindFirstFile($iPath)
    If $FFFF = -1 Then Return -1
    While 1
        $FFNF = FileFindNextFile($FFFF)
        If @error Then ExitLoop
        $STR = StringTrimRight($FFNF, 4)
        GUICtrlCreateTreeViewItem($STR, $tviID)
        GUICtrlSetOnEvent(-1, "Event")
        GUICtrlSetColor(-1, 0x0000C0)
    WEnd
    FileClose($FFFF)
    Return 0
EndFunc

Func _TVGetItemTree($i_treeview, $s_sep_char, $h_tv_item = 0)
    Local $szPath = "", $hParent, $h_item
    If $h_tv_item <> 0 Then
        $h_item = $h_tv_item
    Else
        $h_item = GUICtrlSendMsg($i_treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
    EndIf
    If $h_item > 0 Then
        $szPath = _TVGetItemText($i_treeview, $h_item)
        Do
            $hParent = GUICtrlSendMsg($i_treeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $h_item)
            If $hParent > 0 Then $szPath = _TVGetItemText($i_treeview, $hParent) & $s_sep_char & $szPath
            $h_item = $hParent
        Until $h_item <= 0
    EndIf

    Return $szPath
EndFunc   ;==>_TVGetItemTree

Func _TVGetItemText($i_treeview, $h_item = 0) ; copy, name changed
    Local $s_txt = ""
    If $h_item = 0 Then Return ""
    Local $st_txt = DllStructCreate("char[4096]")
    Local $st_TVI = DllStructCreate("uint;uint;uint;uint;ptr;int;int;int;int;uint;int")
    DllStructSetData($st_TVI, 1, $TVIF_TEXT)
    DllStructSetData($st_TVI, 2, $h_item)
    DllStructSetData($st_TVI, 5, DllStructGetPtr($st_txt))
    DllStructSetData($st_TVI, 6, DllStructGetSize($st_txt))
    If GUICtrlSendMsg($i_treeview, $TVM_GETITEM, 0, DllStructGetPtr($st_TVI)) Then $s_txt = DllStructGetData($st_txt, 1)
    Return $s_txt
EndFunc   ;==>_TVGetText

Cheers

Edited by smashly
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...