Style, LineStyle, Indentation Property (TreeView)

Purpose

Style returns or sets the type of graphics (images, text, plus/minus, and lines) and text that appear for each Node object in a TreeView control.

LineStyle returns or sets the style of lines displayed between Node objects.

Indentation returns or sets the width of the indentation of the Node objects.

Syntax

TreeView.Style [ = value% ]

TreeView.LineStyle [ = value% ]

TreeView.Indentation [ = single ]

Description

The Style property can take one of the tvw-constant values.

tvwTextOnly (0) - Text only.

tvwPictureText (1) - Image and text.

tvwPlusMinusText (2) - Plus/minus and text.

tvwPlusPictureText (3) - Plus/minus, image, and text.

tvwTreeLinesText (4) - Lines and text.

tvwTreeLinesPictureText (5) - Lines, image, and text.

tvwTreeLinesPlusMinusText (6) - Lines, plus/minus, and text.

tvwTreeLinesPlusMinusPictureText (7) - (Default) Lines, plus/minus, image, and text.

If the Style property is set to a value that includes lines, the LineStyle property determines the appearance of the lines. If the Style property is set to a value that does not include lines, the LineStyle property will be ignored.

The LineStyle property can take one of the tvw-constant values.

tvwTreeLines (0) - ( Default) Tree lines. Displays lines between Node siblings and their parent Node.

tvwRootLines (1) - Root Lines. In addition to displaying lines between Node siblings and their parent Node, also displays lines between the root nodes.

You must set the Style property to a style that includes tree lines.

The Indentation property specifies the width (in pixels) that each object is indented. If you change the Indentation property at run time, the TreeView is redrawn to reflect the new width. The property value cannot be negative.

Example

Global a$, n As Int32

Ocx ImageList iml : iml.ImageHeight = 16 : iml.ImageWidth = 16

For n = 1 To 7 : iml.Add , , CreatePicture(LoadIcon(Null, 32511 + n)) : Next n

Ocx TreeView tv = "", 10, 10, 200, 300 : tv.ImageList = iml

For n = 1 To 7

If Odd(n)

tv.Add , , , "Icon" & n, n, n

Else

tv.Add n - 1, tvwChild, , "Icon" & n, n : tv(n).EnsureVisible

EndIf

Next n

Text 220, 13, "Style:" : Ocx ComboBox cb1 = "", 280, 10, 200, 22  : cb1.Sorted = False

For n = 0 To 7 : Read a$ : cb1.AddItem a$, n : Next n

cb1.ListIndex = tv.Style

Text 220, 43, "Line Style:" : Ocx ComboBox cb2 = "", 280, 40, 200, 22 : cb2.Sorted = False

For n = 0 To 1 : Read a$ : cb2.AddItem a$, n : Next n

cb2.ListIndex = tv.LineStyle

Text 220, 73, "Indentation:" : Ocx TextBox tb = "", 280, 72, 40, 14 : tb.BorderStyle = 1 : tb.ReadOnly = True

Ocx UpDown up : up.BuddyControl = tb  : .Max = 40 : .Value = tv.Indentation

Do : Sleep : Until Me Is Nothing

 

Sub cb1_Click

If tv.Style <> cb1.ItemData(cb1.ListIndex) Then tv_Redraw

EndSub

 

Sub cb2_Click

If tv.LineStyle = cb2.ItemData(cb2.ListIndex) Then tv_Redraw

EndSub

 

Sub up_Change

tv.Indentation = up.Value

EndSub

 

Sub tv_Redraw

// Changing the Style and LineStyle values once the treeview has...

// ...been drawn can lead to some odd results, so it is necesaary...

// ...to redraw it upon every change to show it correctly.

Set tv = Nothing

Ocx TreeView tv = "", 10, 10, 200, 300 : tv.ImageList = iml

tv.Style = cb1.ItemData(cb1.ListIndex)

tv.LineStyle = cb2.ItemData(cb2.ListIndex)

For n = 1 To 7

If Odd(n)

tv.Add , , , "Icon" & n, n, n

Else

tv.Add n - 1, tvwChild, , "Icon" & n, n : tv(n).EnsureVisible

EndIf

Next n

EndSub

Data tvwTextOnly,tvwPictureText,tvwPlusMinusText,tvwPlusPictureText,tvwTreeLinesText

Data tvwTreeLinesPictureText,tvwTreeLinesPlusMinusText,tvwTreeLinesPlusMinusPictureText

Data tvwTreeLines,tvwRootLines

See Also

TreeView

{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}