How to Use Treeview in VB6

104 31
    • 1). Create a new Standard EXE Visual Basic project. Click "Components" from the "Project" menu, and select "Microsoft Windows Common Controls 6.0 (SP6)." This adds the TreeView control to the VB ToolBox.

    • 2). Select the "TreeView" control and click on "Form1" that was created by default. Hold the left mouse button, drag the mouse across the form and release the mouse button. This creates a TreeView control as wide as your mouse drag. Click on the "TreeView" control after it appears on the form and drag to expand any of the blue dots surrounding the other edge to resize the control.

    • 3). Select "ImageList" from the "ToolBox" and click on "Form1" to create a new ImageList control. Right-click on the newly created "ImageList1" and select "Properties." Click on the "Images" tab and click the "Insert Picture" button to add images to the control. Assign the "ImageList" to the TreeView control by typing the following code in the "Form1_Load" event: "Set TreeView1.ImageList = ImageList1."

    • 4). Define a variable of type "Node" in the "Form1_Load" event. Set that variable equal to "TreeView1.Nodes.Add(, , , "First Level", "FirstImage")." This code creates the first node in the TreeView displayed as "FirstLevel". The image displayed is the image with the key value of "FirstImage" in the "ImageList" control.

    • 5). Add child nodes, displayed below the words "FirstLevel" by setting the node variable equal to "TreeView1.Nodes.Add(myNode, tvwChild, , "SecondLevel", "SecondImage")" in the "Form1_Load" event. The TreeView will look like this to the end-user:

      FirstLevel

      SecondLevel

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.