Jump to content

Create TreeView from INI file


kpu
 Share

Recommended Posts

How can I create a TreeView from an ini File. I have around 700 sections in an INI file that look like the following:

[kpu-24]Administrators=Administrator|Kane|Domain Admins|Kane

Backup Operators=

Guests=Guest

Network Configuration Operators=

Power Users=

Remote Desktop Users=

Replicator=

Users=INTERACTIVE|Authenticated Users|Kane1|Domain Users

HelpServicesGroup=

__vmware__=__vmware_user__

I would like to make it so it would be [Machine]-[Groups]-[users] like this:

$TreeView1 = GUICtrlCreateTreeView(344, 344, 225, 73)
$Computer = GUICtrlCreateTreeViewItem("Computer", $TreeView1)
$Groups = GUICtrlCreateTreeViewItem("Groups", $Computer)
$Users = GUICtrlCreateTreeViewItem("Users", $Groups)

I would think I would need to create an array, but how do I get it to read it correctly?

Any help would greatly be appreciated.

Link to comment
Share on other sites

Okay, I think I'm getting closer. This works if I call the section... I guess I'll need to look at the "IniReadSectionNames" next...

Func _IniReadInfo()
$var = IniReadSection($file,"kpu-24")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    $TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)
    For $i = 1 To $var[0][0]
        GUICtrlCreateTreeViewItem($var[$i][0], $TreeView1)
       ;MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF );& "Value: " & $var[$i][1])
    Next
EndIf
EndFunc
Edited by kpu
Link to comment
Share on other sites

I once had this problem too: but i scrapped the idea of having a treeview for an alternative:

Screenshot of GUI created by UDF:

t.bmp

;===============================================================================
;
; Function Name:    _EditIniDialog()
; Description:    Opens a dialog to edit an INI file.
; Parameter(s):  $iniloc         - Path to the INI file
;                  $EIDtitle       - [optional] Title of the window. Default is "INI Editor"
;                  $DisallowSaveAs - [optional] If set to a non-zero value, it disables the save-as option (saving in
;                                    original location still allowed). (Default = 0)
;                  $DisallowEdit   - [optional] If set to a non-zero value, it disallows clicking any button except
;                                    for the Close button(save-as option still allowed unless previous option sets otherwise). (Default = 0)
; Requirement(s):   AutoIt
; Return Value(s):  Returns 1 if no error
;                  Returns 0 if there is an error
;                  @error = 1 - Unable to read section names of file (ini may not exist)
;                  @error = 2 - There was an error while reading a section (ini does exist)
;                  @error = 3 - Error while copying files (ini does exist)
; Author(s):        Alexander "TechDude" Wood (aka nfwu)   me@techdudeonline.tk
;
;===============================================================================
#include <File.au3>
#include <Misc.au3>
Func _DialogEditIni($iniloc, $EIDtitle = "INI Editor", $DisallowSaveAs = 0, $DisallowEdit = 0)
    If Not IsDeclared('WS_CLIPSIBLINGS') Then Global Const $WS_CLIPSIBLINGS = 0x04000000
    If Not IsDeclared('WS_OVERLAPPEDWINDOW') Then Global Const $WS_OVERLAPPEDWINDOW = 0x00CF0000
    If Not IsDeclared('WS_VISIBLE') Then Global Const $WS_VISIBLE = 0x10000000
;GUI
    Local $EditIniDialog = GUICreate(_Iif ($DisallowEdit == 0, $EIDtitle, $EIDtitle & "(Read-Only)"), 392, 323, (@DesktopWidth - 392) / 2, (@DesktopHeight - 323) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
;Labels
    GUICtrlCreateLabel("Section:", 10, 10, 100, 20)
    GUICtrlCreateLabel("Key/Value Pairs:", 10, 90, 110, 20)
;Section Ctrls
    Local $SectionCombo = GUICtrlCreateCombo("", 10, 30, 370, 21)
    Local $SectionNewButton = GUICtrlCreateButton("New Section", 10, 60, 110, 20)
    Local $SectionDelButton = GUICtrlCreateButton("Delete Section", 140, 60, 110, 20)
    Local $SectionEdiButton = GUICtrlCreateButton("Edit Section", 270, 60, 110, 20)
;Pairs Ctrls
    Local $PairList = GUICtrlCreateList("", 10, 110, 370, 123)
    Local $PairNewButton = GUICtrlCreateButton("New Pair", 10, 240, 110, 20)
    Local $PairDelButton = GUICtrlCreateButton("Delete Pair", 140, 240, 110, 20)
    Local $PairEdiButton = GUICtrlCreateButton("Edit pair", 270, 240, 110, 20)
;Save Buttons
    Local $SaveSavButton = GUICtrlCreateButton("Save", 10, 290, 110, 20)
    Local $SaveSasButton = GUICtrlCreateButton("Save As...", 140, 290, 110, 20)
    Local $SaveCloButton = GUICtrlCreateButton("Close", 270, 290, 110, 20)
;Data
    Local $SectionNames = IniReadSectionNames($iniloc)
    Local $SectionNamesList = ""
    Local $PairData
    Local $PairString = ""
    Local $tempfile = _TempFile ()
    Local $actualini = $iniloc
    If @error Then
        GUISetState(@SW_HIDE, $EditIniDialog)
        SetError(1)
        Return 0
    EndIf
    If Not FileCopy($iniloc, $tempfile) Then
        GUISetState(@SW_HIDE, $EditIniDialog)
        SetError(3)
        Return 0
    EndIf
    $iniloc = $tempfile
    $SectionNamesList = $SectionNames[1]
    For $i = 2 To $SectionNames[0]
        $SectionNamesList = $SectionNamesList & "|" & $SectionNames[$i]
    Next
    GUICtrlSetData($SectionCombo, $SectionNamesList, $SectionNames[1])
    $PairData = _DialogEditIni_Helper($iniloc, $SectionNames[1], $PairString)
    If @error Then Return 0
    GUICtrlSetData($PairList, $PairString)
    GUISetState(@SW_SHOW, $EditIniDialog)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg == $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE, $EditIniDialog)
                GUIDelete( $EditIniDialog )
                Return 1
            Case $msg == $SaveCloButton
                GUISetState(@SW_HIDE, $EditIniDialog)
                GUIDelete( $EditIniDialog )
                Return 1
            Case $msg == $SectionCombo
                $sec = GUICtrlRead($SectionCombo)
                $PairData = _DialogEditIni_Helper($iniloc, $sec, $PairString)
                If @error Then
                    SetError(2)
                    GUISetState(@SW_HIDE, $EditIniDialog)
                    GUIDelete( $EditIniDialog )
                    Return
                EndIf
                GUICtrlSetData($PairList, "")
                GUICtrlSetData($PairList, $PairString)
            Case Else
                If (Not $DisallowSaveAs) And ($msg == $SaveSasButton) Then
                    $file = FileSaveDialog($EIDtitle & " - Save .ini As...", ".", "Files (*.ini)", 1 + 16 + 2, $actualini)
                    If @error Then
                        MsgBox(262208, $EIDtitle, "Save Cancelled")
                    Else
                        If Not FileCopy($tempfile, $file) Then
                            GUISetState(@SW_HIDE, $EditIniDialog)
                            SetError(3)
                            GUIDelete( $EditIniDialog )
                            Return 0
                        EndIf
                        MsgBox(262208, $EIDtitle, "Ini [" & $file & "] Saved.")
                    EndIf
                ElseIf ($DisallowSaveAs) And ($msg == $SaveSasButton) Then
                    MsgBox(262160, $EIDtitle & " - Error", "The [Save As...] function has been disabled." & @CRLF & "You are not allowed to save the file in a location other than the original.")
                EndIf
                If Not $DisallowEdit Then
                    Select
                        Case $msg == $SaveSavButton
                            If Not FileCopy($tempfile, $actualini) Then
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                SetError(3)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            MsgBox(262208, $EIDtitle, "Ini [" & $iniloc & "] Saved.")
                            SetError(0)
                            GUIDelete( $EditIniDialog )
                            Return 1
                        Case $msg == $SectionDelButton
                            $sec = GUICtrlRead($SectionCombo)
                            $iMsgBoxAnswer = MsgBox(262436, $EIDtitle, "Are you sure you want to delete the [Section]: " & $sec & "?")
                            Select
                                Case $iMsgBoxAnswer = 6;Yes
                                    IniDelete($iniloc, $sec)
                                    _DialogEditIni_Helper4($iniloc, $SectionNames, $SectionNamesList)
                                    GUICtrlSetData($SectionCombo, "")
                                    GUICtrlSetData($SectionCombo, $SectionNamesList, $SectionNames[1])
                                    $PairData = _DialogEditIni_Helper($iniloc, $SectionNames[1], $PairString)
                                    If @error Then
                                        SetError(2)
                                        GUISetState(@SW_HIDE, $EditIniDialog)
                                        GUIDelete( $EditIniDialog )
                                        Return 0
                                    EndIf
                                    GUICtrlSetData($PairList, "")
                                    GUICtrlSetData($PairList, $PairString)
                                Case $iMsgBoxAnswer = 7;No
                            EndSelect
                        Case $msg == $SectionNewButton
                            $sec = InputBox($EIDtitle, "Please enter the name of the new [Section]:")
                            IniWrite($iniloc, $sec, "DeleteMe", "TempValue")
                            _DialogEditIni_Helper4($iniloc, $SectionNames, $SectionNamesList)
                            GUICtrlSetData($SectionCombo, "")
                            GUICtrlSetData($SectionCombo, $SectionNamesList, $sec)
                            $PairData = _DialogEditIni_Helper($iniloc, $sec, $PairString)
                            If @error Then
                                SetError(2)
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            GUICtrlSetData($PairList, "")
                            GUICtrlSetData($PairList, $PairString)
                        Case $msg == $SectionEdiButton
                            $sec = GUICtrlRead($SectionCombo)
                            $sec2 = InputBox($EIDtitle, "Please enter the new name of the [Section]" & $sec & ":", $sec)
                            IniRenameSection ($iniloc, $sec, $sec2)
                            _DialogEditIni_Helper4($iniloc, $SectionNames, $SectionNamesList)
                            GUICtrlSetData($SectionCombo, "")
                            GUICtrlSetData($SectionCombo, $SectionNamesList, $sec2)
                            $PairData = _DialogEditIni_Helper($iniloc, $sec2, $PairString)
                            If @error Then
                                SetError(2)
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            GUICtrlSetData($PairList, "")
                            GUICtrlSetData($PairList, $PairString)
                        Case $msg == $PairNewButton
                            $sec = GUICtrlRead($SectionCombo)
                            $key = InputBox($EIDtitle, "Please enter the [Key] of the new [Pair]:")
                            $pair = InputBox($EIDtitle, "Please enter the [Value] of the new [Pair]:")
                            IniWrite($iniloc, $sec, $key, $pair)
                            _DialogEditIni_Helper4($iniloc, $SectionNames, $SectionNamesList)
                            GUICtrlSetData($SectionCombo, "")
                            GUICtrlSetData($SectionCombo, $SectionNamesList, $sec)
                            $PairData = _DialogEditIni_Helper($iniloc, $sec, $PairString)
                            If @error Then
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                SetError(2)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            GUICtrlSetData($PairList, "")
                            GUICtrlSetData($PairList, $PairString)
                        Case $msg == $PairDelButton
                            $sec = GUICtrlRead($SectionCombo)
                            $pair = _DialogEditIni_Helper3($PairList, $PairData)
                            IniDelete($iniloc, $sec, $PairData[$pair][0])
                            $PairData = _DialogEditIni_Helper($iniloc, $sec, $PairString)
                            If @error Then
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                MsgBox(262192 + 64, $EIDtitle, "NOTE: If you tried to delete the last value in a section, do not do so." & @CRLF & "It will not work. Instead, delete the section." & @CRLF & "@ERROR = 2")
                                SetError(2)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            GUICtrlSetData($PairList, "")
                            GUICtrlSetData($PairList, $PairString)
                        Case $msg == $PairEdiButton
                            $sec = GUICtrlRead($SectionCombo)
                            $pair = _DialogEditIni_Helper3($PairList, $PairData)
                            IniDelete($iniloc, $sec, $PairData[$pair][0])
                            $key = InputBox($EIDtitle, "Please enter the new [Key] of the [Pair]:", $PairData[$pair][0])
                            $value5 = InputBox($EIDtitle, "Please enter the new [Value] of the [Pair]:", $PairData[$pair][1])
                            IniWrite($iniloc, $sec, $key, $value5)
                            _DialogEditIni_Helper4($iniloc, $SectionNames, $SectionNamesList)
                            GUICtrlSetData($SectionCombo, "")
                            GUICtrlSetData($SectionCombo, $SectionNamesList, $sec)
                            $PairData = _DialogEditIni_Helper($iniloc, $sec, $PairString)
                            If @error Then
                                GUISetState(@SW_HIDE, $EditIniDialog)
                                SetError(2)
                                GUIDelete( $EditIniDialog )
                                Return 0
                            EndIf
                            GUICtrlSetData($PairList, "")
                            GUICtrlSetData($PairList, $PairString)
                    EndSelect
                ElseIf $msg == $SectionDelButton Or $msg == $SectionDelButton Or _
                        $msg == $SectionEdiButton Or $msg == $PairNewButton Or _
                        $msg == $PairDelButton Or $msg == $PairEdiButton Or $msg == $SaveSavButton Then
                    MsgBox(262160, $EIDtitle & " - Error", "You are in (Read-Only) Mode." & @CRLF & "You are not allowed to edit the data")
                EndIf
        EndSelect
    WEnd
    GUIDelete( $EditIniDialog )
EndFunc;==>_DialogEditIni
Func _DialogEditIni_Helper($file, $sec, ByRef $string)
    Local $data = IniReadSection($file, $sec)
    If @error == 2 Then
        SetError(0)
        Return ""
    ElseIf @error == 1 Then
        SetError(2)
        $string = "Error : Code 2|File:" & $file & "|Section:" & $sec
        Return 0
    EndIf
    $string = _DialogEditIni_Helper2($data[1][0], $data[1][1])
    For $i = 2 To $data[0][0]
        $string = $string & "|" & _DialogEditIni_Helper2($data[$i][0], $data[$i][1])
    Next
    Return $data
EndFunc;==>_DialogEditIni_Helper
Func _DialogEditIni_Helper2($v1, $v2)
    Return $v1 & " - " & $v2
EndFunc;==>_DialogEditIni_Helper2
Func _DialogEditIni_Helper3($PairList, $PairData)
    $pairval = GUICtrlRead($PairList)
    For $i = 1 To $PairData[0][0]
        If $pairval == _DialogEditIni_Helper2($PairData[$i][0], $PairData[$i][1]) Then
            Return $i
        EndIf
    Next
EndFunc;==>_DialogEditIni_Helper3
Func _DialogEditIni_Helper4($iniloc, ByRef $SectionNames, ByRef $SectionNamesList)
    $SectionNames = IniReadSectionNames($iniloc)
    $SectionNamesList = $SectionNames[1]
    For $i = 2 To $SectionNames[0]
        $SectionNamesList = $SectionNamesList & "|" & $SectionNames[$i]
    Next
EndFunc;==>_DialogEditIni_Helper4

The Code saves a copy of the INI first, and modifies that copy. When the user presses save, the copy is copied to the original location.

EDIT:

<!--

[attachmentid=5579]
--> < pretend not to see this

t.au3

Edited by nfwu
Link to comment
Share on other sites

I once had this problem too: but i scrapped the idea of having a treeview for an alternative:

Thanks, but this has to be able to be done...somehow. :P

I think I'm getting closer. Can someon look at this? I get an error on line 48:

For $i = 1 To $var[0][0]

For $i = 1 To $var^ ERROR

#include <GuiConstants.au3>
#include <file.au3>
#include <array.au3>
Dim $e, $i, $var, $file, $TreeView, $TreeView1, $var2, $TreeView2
Dim $TreeView3, $test1, $varx
Dim $var, $file, $x
$file = "logfile1.ini"

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("Form2", 420, 331, 430,346 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

;_IniReadInfo()
_IniGetSectionNames()
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit

Func _IniGetSectionNames()
$varx = IniReadSectionNames($file)
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $x = 1 To $varx[0]
        MsgBox(4096, "", $varx[$x])
        _IniReadInfo()
    Next
EndIf
EndFunc

Func _IniReadInfo()
;MsgBox(32,"VarX","Varx = " & $varx[$x])
$var = IniReadSection($file,$varx[$x])
$TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    $TreeView2 = GUICtrlCreateTreeViewitem("KPU-24",$TreeView1)
    For $i = 1 To $var[0][0]
    GUICtrlCreateTreeViewItem($var[$i][0], $TreeView2)
       MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF );& "Value: " & $var[$i][1])
    Next
EndIf
EndFunc
Link to comment
Share on other sites

You were really close, give it a try.....

#include <GuiConstants.au3>
#include <file.au3>
#include <array.au3>
Dim $e, $i, $var, $file, $TreeView, $TreeView1, $var2, $TreeView2
Dim $TreeView3, $test1, $varx
Dim $var, $file, $x
$file = "logfile1.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("Form2", 420, 331, 430,346 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)

;_IniReadInfo()
_IniGetSectionNames()
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
  ;;;
    EndSelect
WEnd
Exit

Func _IniGetSectionNames()
    $varx = IniReadSectionNames($file)
    If @error Then 
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        For $x = 1 To $varx[0]
    ;MsgBox(4096, "", $varx[$x])
            _IniReadInfo($varx[$x])
        Next
    EndIf
EndFunc

Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $TreeView2 = GUICtrlCreateTreeViewitem($sSection, $TreeView1)
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $TreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                if $sValue[$x] <> '' Then $TreeView4 = GUICtrlCreateTreeViewitem($sValue[$x], $TreeView3)
            Next
        Next
    EndIf
EndFunc

Keep in mind that when you used varibles inside functions those varible are only good for that function if you want to used with multipler funtions then you have to declare them as Global. You used $varx for _IniGetSectionNames() when you try to used with _IniReadInfo() you where loosing $varx values.

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Keep in mind that when you used varibles inside functions those varible are only good for that function if you want to used with multipler funtions then you have to declare them as Global. You used $varx for _IniGetSectionNames() when you try to used with _IniReadInfo() you where loosing $varx values.

Thanks, I thought something was going on with that since when I called the variable in the second function it returned a 2...

Thanks again, it seems you are always helping me out. :P. I started doing this with combobox's, but then thought treeview would look much better.

Link to comment
Share on other sites

yes it is, if you want someone to do the work for you, you should ask more directly...

As you read my posts, you should be able to tell that I make the effort to try and make it work myself. I don't have a lick of programming background and still have a lot to learn. If you say "yes it is" then I will research it as best I can, try and write some code, and if I can't get it to work. I'll see if I can get some help from some of the "Pro's" around here. But hey, thanks for the unnecessary criticism. :P

Link to comment
Share on other sites

As you read my posts, you should be able to tell that I make the effort to try and make it work myself. I don't have a lick of programming background and still have a lot to learn. If you say "yes it is" then I will research it as best I can, try and write some code, and if I can't get it to work. I'll see if I can get some help from some of the "Pro's" around here. But hey, thanks for the unnecessary criticism. :P

i really am sorry, that was meant entirely as a joke, and i meant no offense.
Link to comment
Share on other sites

Is it possible to create a search box so you can find a PC in the list?

To acomplish the search and make your script user friendly by:

1) Sorting the Treeview alphabetic order

2) Creating a combobox with all the computer name alphabetic order also

3) Adding a tiny button with DEFPUSHBUTTON style. When I said tiny I mean it, it is only 1 pixel by 1 pixel so no one cannot see it. I know I can used GUICtrlState() to hide the button but I was trying to save space without adding another line to the code.

4) Adding and Deleting a new section in the inifile. The new section is called [TreeViewHandle] which record all the controlid everytime the script add a new computername to the listview and combobox.

The reason of the button is if you type the computer name at the combobox and then hit enter the script will do the search. If the compter name typed is not at the combobox list it will give a message to the user that specific computer is not on the list. When the computer is found on the list, the script will expand that computer with all the groups.

#include <GuiConstants.au3>
#include <GuiTreeView.au3>
#include <GuiCombo.au3>
#include <file.au3>
#include <array.au3>
Dim $e, $i, $var, $file, $TreeView, $TreeView1, $var2, $TreeView2
Dim $TreeView3, $test1, $varx
Dim $var, $file, $x
$file = "logfile1.ini"

$MainGui = GuiCreate("Form2", 420, 331, 430,346 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)
GUICtrlCreateLabel("Select Computer Name ====>", 16, 255, 200, 20)
$ComboBox = GUICtrlCreateCombo('',170, 250, 200, 20, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL, $WS_VSCROLL, $CBS_SORT))
$Button = GUICtrlCreateButton ('',  155, 260, 1, 1, $BS_DEFPUSHBUTTON)

IniDelete($file, 'TreeViewHandle')
_IniGetSectionNames()
_GUICtrlTreeViewSort($TreeView1)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
                                IniDelete($file, 'TreeViewHandle')      
        ExitLoop
    Case $msg = $ComboBox Or $msg = $Button
        $SearchCompter = GUICtrlRead($ComboBox)
        $handle = IniRead($file, 'TreeViewHandle', $SearchCompter, '')
        If $handle == '' Then 
            GUICtrlSetData($ComboBox, '')
            MsgBox(0, 'Not Found', 'Computer ' & $SearchCompter & ' is not on the list.')
        EndIf
        If $handle <> '' Then
            _GUICtrlTreeViewExpand ($MainGui, $TreeView1, 0)
            Sleep(500)
            _GUICtrlTreeViewExpand ($MainGui, $TreeView1, 1, $handle)
            
        EndIf
        
    Case $msg = $TreeView1
        MsgBox(0, '', 'TreeView')

    Case Else
;;;
    EndSelect
WEnd
Exit

Func _IniGetSectionNames()
    $varx = IniReadSectionNames($file)
    If @error Then 
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        For $x = 1 To $varx[0]
            _IniReadInfo($varx[$x])
        Next
    EndIf
EndFunc

Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $TreeView2 = GUICtrlCreateTreeViewitem($sSection, $TreeView1)
        _GUICtrlComboAddString($ComboBox, $sSection)
        IniWrite($file, 'TreeViewHandle', $sSection, $TreeView2)
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $TreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                if $sValue[$x] <> '' Then $TreeView4 = GUICtrlCreateTreeViewitem($sValue[$x], $TreeView3)
            Next
        Next
    EndIf
EndFunc
Keep in mind this is not a fast search so the bigger the list the longest the search...

:P Enjoy it!!!

Edited by Danny35d
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

  • 1 year later...

#include <GuiConstants.au3>
#include <file.au3>
#include <array.au3>
Dim $e, $i, $var, $file, $TreeView, $TreeView1, $var2, $TreeView2
Dim $TreeView3, $test1, $varx
Dim $var, $file, $x
$file = "logfile1.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000
GuiCreate("Form2", 420, 331, 430,346 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$TreeView1 = GUICtrlCreateTreeView(16, 16, 353, 217)

;_IniReadInfo()
_IniGetSectionNames()
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
 ;;;
    EndSelect
WEnd
Exit

Func _IniGetSectionNames()
    $varx = IniReadSectionNames($file)
    If @error Then 
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        For $x = 1 To $varx[0]
   ;MsgBox(4096, "", $varx[$x])
            _IniReadInfo($varx[$x])
        Next
    EndIf
EndFunc

Func _IniReadInfo($sSection)
    Dim $sValue
    $var = IniReadSection($file, $sSection)
    If @error Then
        MsgBox(4096, "", "Error occured, probably no INI file.")
    Else
        $TreeView2 = GUICtrlCreateTreeViewitem($sSection, $TreeView1)
        For $i = 1 To $var[0][0]
            $TreeView3 = GUICtrlCreateTreeViewItem($var[$i][0], $TreeView2)
            $sValue = StringSplit($var[$i][1], '|')
            For $x = 1 To $sValue[0]
                if $sValue[$x] <> '' Then $TreeView4 = GUICtrlCreateTreeViewitem($sValue[$x], $TreeView3)
            Next
        Next
    EndIf
EndFunc

logfile1.ini

[1]
Name=joj
LastName=jej

I want to know how to make treeview items but to be like this:

-1

Name=joj

LastName=jej

not like this:

-1

-Name

joj

-LastName

jej

:|

[quote name='dbzfanatic' post='609696' date='Nov 26 2008, 08:46 AM']This is a help forum not a "write this for me" forum.[/quote](Sorry for bad English) :)

Link to comment
Share on other sites

$ld_val = your ini

$treeview1 = $treeview ID

$progress = 0 off, 1 0n

#include <guitreeview.au3>
   #include <guiconstants.au3>
   $ld_val = 'C:\my_file.ini'

    
    Func Ini_TO_Treeview($lv_val, $Treeview1, $Progress = '0' )
    _GUICtrlTreeViewDeleteAllItems( $TreeView1 )
    GuiCtrlSetState( $Treeview1, $GUI_Show )
    Global $secs = IniReadSectionNames( $ld_val )
    If IsArray( $secs ) Then
    If $progress = '1' then ProgressOn( "Reading INI 2 Treeview", "Working..." )
    $total = $secs[0]
    Dim $a[999]
    For $i = 1 to $secs[0]-1 step 1
        $a[$i] = GUICtrlCreateTreeViewItem( $secs[$i], $TreeView1 )
        $b = IniReadSection( $ld_val, $secs[$i] )
        If @error <> 1 Then
        For $c = 1 to $b[0][0] step 1
            GUICtrlCreateTreeViewItem( $b[$c][1], $a[$i] )
        Next
        Endif
    If $progress = '1' then ProgressSet( (($i/$total)*100)-1, "Reading INI 2 Treeview", "Placing into a Treeview" )
    Next
    Endif
    EndFunc

[center][/center]

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...