Step 2: Read the Data and Build the Outline

Double-click the form and add the following code to the Form_Load event:

    Private Sub Form_Load()

   

        ' suspend repainting to increase speed

        fg.Redraw = False

   

        ' populate the control

        AddNode "Win.ini"

        AddNode "System.ini"

        AddNode "vb.ini"

   

        ' expand outline, resize to fit, collapse outline

        fg.Outline -1

        fg.AutoSize 1, 2

        fg.Outline 1

   

        ' repainting is back on

        fg.Redraw = True

    End Sub

The routine starts by setting the Redraw property to False. This suspends repainting while we populate the control, and increases speed significantly.

Then the AddNode routine is called to populate the control with the contents of three .INI files which you are likely to have on your system: Win, System, and Vb. The AddNode routine is shown below.

Finally, the outline is totally expanded, the AutoSize method is called to adjust column widths to their contents, and the outline is collapsed back to level 1 so the file and section nodes will be displayed.

The AddNode routine does most of the work. It reads an .INI file and populates the control, creating nodes and branches according to the contents of the file. Here is the AddNode routine:

    Sub AddNode(inifile As String)

        Dim ln As String, p As Integer

        With fg

     

        ' create file node

        .AddItem inifile

        .IsSubtotal(Rows - 1) = True

        .Cell(flexcpFontBold, Rows - 1, 0) = True

     

        ' read ini file

        Open "c:\windows\" & inifile For Input As #1

        While Not EOF(1)

            Line Input #1, ln

       

            ' if this is a section, add node

            If Left(ln, 1) = "[" Then

                .AddItem Mid(ln, 2, Len(ln) - 2)

                .IsSubtotal(Rows - 1) = True

                .RowOutlineLevel(Rows - 1) = 1

                .Cell(flexcpFontBold, Rows - 1, 0) = True

           

            ' if this is regular data, add branch

            ElseIf InStr(ln, "=") > 0 Then

                p = InStr(ln, "=")

                .AddItem vbTab & Left(ln, p - 1) & vbTab & Mid(ln, p + 1)

            End If

        Wend

        Close #1

        End With

    End Sub

The AddNode routine is a little long, but it is fairly simple. It starts by adding a row containing the name of the .INI file being read. It marks the row as a subtotal using the IsSubtotal property so the control will recognize it as an outline node.

Next, the routine reads the INI file line by line. Section names are enclosed in square brackets. The code adds them to the control and then marks them as subtotals much the same way it marked the file name. The difference is that here it also sets the RowOutlineLevel property to 1, indicating this node is a child of the previous level-0 node (the one that contains the file name).

Finally, lines containing data are parsed into tokens and settings and then added to the control. They are not marked as subtotals.