SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftMask/OCX 7.0 - Masked Edit Control
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftPrintPreview/DLL 2.0 - Print Preview Control (discontinued)
SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftDirectory 3.5 - File/Folder Control (discontinued)
SftMask/OCX 7.0 - Masked Edit Control
SftOptions 1.0 - Registry/INI Control (discontinued)
SftPrintPreview/OCX 1.0 - Print Preview Control (discontinued)
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftTabs/NET 6.0 - Tab Control (discontinued)
SftTree/NET 2.0 - Tree Control
This sample illustrates sorting, column reordering, responding to column header clicks, context menus, controlling expand/collapse buttons and plus/minus graphics.
The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 7.5\Samples\VB6\BookTable\Form1.frm or C:\Program Files\Softelvdm\SftTree OCX 7.5\Samples\VB6\BookTable\Form1.frm (on 32-bit Windows versions).
Option Explicit
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
Dim Bk As Integer, Ch As Integer, Sect As Integer, ItemIndex As Integer
Dim BookIndex As Integer
Dim size As Integer
Dim CellFont As New StdFont
Randomize
With SftTree1
' Mass-Update
.BulkUpdate = True
' set default item graphic. This can also be done at design time
Set .Items.ItemImageExpandable.Picture = BookClosed.Picture
Set .Items.ItemImageExpanded.Picture = BookOpen.Picture
Set .Items.ItemImageLeaf.Picture = Topic.Picture
' set the column header sort indicators
SftTree1.Headers.SortIndicators = headerSortIndicatorsSftTreeAuto
SftTree1.Header(0).SortIndicator = sortIndicatorSftTreeAscending
' set the cell font for books
Set CellFont = Font
CellFont.Bold = True
' Add all available options
For Bk = 1 To 4
' add a book
BookIndex = .Items.Add("Book " & Bk)
.Cell(BookIndex, 1).Text = "Description for book " & Bk
size = Int((1000 * Rnd) + 1)
.Cell(BookIndex, 2).Text = size
.Item(BookIndex).Data = size
' add chapters
For Ch = 1 To 2
ItemIndex = .Items.Add("Chapter " & Ch)
.Item(ItemIndex).Level = 1
' add sections
For Sect = 1 To 2
ItemIndex = .Items.Add("Section " & Sect)
.Item(ItemIndex).Level = 2
Next Sect
Next Ch
' after adding the book and all dependent items, we
' collapse the item, so it's up to the user to expand it
.Item(BookIndex).Collapse False
' set font
Set .Cell(BookIndex, 0).Font = CellFont
Next Bk
' End of Mass-Update
.BulkUpdate = False
' Make columns optimal
.ColumnsObj.MakeOptimal
' allow horizontal scrolling
.Items.RecalcHorizontalExtent
End With
End Sub
Private Sub ShowPlusMin_Click()
If ShowPlusMin.Value = 0 Then
SftTree1.Items.PlusMinusImageExpandable.Clear
SftTree1.Items.PlusMinusImageExpanded.Clear
Else
Set SftTree1.Items.PlusMinusImageExpandable.Picture = Plus.Picture
Set SftTree1.Items.PlusMinusImageExpanded.Picture = Minus.Picture
End If
End Sub
Private Sub Ugly_Click()
If Ugly.Value = 0 Then
SftTree1.ButtonPicture = Nothing
Else
Set SftTree1.ButtonPicture = UglyButtons.Picture
End If
End Sub
Private Sub SortHeader()
With SftTree1
Dim SortedColumn As Integer
' get the new, sorted column
SortedColumn = .Headers.SortedColumn
' Sort the data based on the sort indicator
' Note that column 2 is sorted by Item.Data, which is an integer value (book size in pages)
If .Header(SortedColumn).SortIndicator = sortIndicatorSftTreeAscending Then
If SortedColumn = 2 Then
.Items.SortDependents -1, SortedColumn, sortSftTreeAscItemData
Else
.Items.SortDependents -1, SortedColumn, sortSftTreeAscending
End If
Else
If SortedColumn = 2 Then
.Items.SortDependents -1, SortedColumn, sortSftTreeDscItemData
Else
.Items.SortDependents -1, SortedColumn, sortSftTreeDescending
End If
End If
End With
End Sub
Private Sub HeaderMenu()
Dim Count As Integer
Count = 0
If SftTree1.Column(0).WidthPix > 0 Then
MenuForm.ShowContents.Checked = True
Count = Count + 1
Else
MenuForm.ShowContents.Checked = False
End If
If SftTree1.Column(1).WidthPix > 0 Then
MenuForm.ShowDescription.Checked = True
Count = Count + 1
Else
MenuForm.ShowDescription.Checked = False
End If
If SftTree1.Column(2).WidthPix > 0 Then
MenuForm.ShowSize.Checked = True
Count = Count + 1
Else
MenuForm.ShowSize.Checked = False
End If
If Count <= 1 Then
If MenuForm.ShowContents.Checked Then MenuForm.ShowContents.Enabled = False
If MenuForm.ShowDescription.Checked Then MenuForm.ShowDescription.Enabled = False
If MenuForm.ShowSize.Checked Then MenuForm.ShowSize.Enabled = False
Else
MenuForm.ShowContents.Enabled = True
MenuForm.ShowDescription.Enabled = True
MenuForm.ShowSize.Enabled = True
End If
MenuForm.ShowAll.Enabled = Count < 3
SftTree1.CancelMode
PopupMenu MenuForm.HeaderPopup
End Sub
Private Sub SftTree1_ContextMenu(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
' Determine click context menu for header or item
Dim l As Single, t As Single, h As Single, w As Single
SftTree1.Headers.GetPosition l, t, w, h
If X >= l And X < l + w And Y >= t And Y <= t + h Then
HeaderMenu
Exit Sub
End If
' determine item right-clicked
Dim ItemIndex As Long
ItemIndex = SftTree1.Items.HitTest(X, Y)
If ItemIndex >= 0 And ItemIndex < SftTree1.Items.Count Then
SftTree1.Items.Current = ItemIndex
SftTree1.Item(ItemIndex).Selected = True
SftTree1.CancelMode
PopupMenu MenuForm.ItemPopup
End If
End Sub
Private Sub SftTree1_ItemClick(ByVal ItemIndex As Long, ByVal ColIndex As Integer, ByVal AreaType As Integer, ByVal Button As Integer, ByVal Shift As Integer)
With SftTree1
If AreaType = constSftTreeColumn And Button = constSftTreeLeftButton Then
SortHeader
ElseIf AreaType = constSftTreeExpandAll Then
.Item(ItemIndex).Expand False, True
End If
End With
End Sub
Private Sub SftTree1_ItemDblClick(ByVal ItemIndex As Long, ByVal ColIndex As Integer, ByVal AreaType As Integer, ByVal Button As Integer, ByVal Shift As Integer)
With SftTree1
If AreaType = constSftTreeColumnRes And Button = constSftTreeLeftButton Then
.Column(ColIndex).MakeOptimal
.Items.RecalcHorizontalExtent
ElseIf AreaType = constSftTreeColumn And Button = constSftTreeLeftButton Then
SortHeader
End If
End With
End Sub