HeaderPane
Main
Hide

SftTree/OCX 8.0 - ActiveX Tree Control

Share Link
Print

XMLLoadSave Sample (VB6)

This sample illustrates saving the tree control's contents to an XML file and loading them back, using both flat and nested (hierarchical) XML formats.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 8.0\Samples\VB6\XMLLoadSave\Form1.frm or C:\Program Files\Softelvdm\SftTree OCX 8.0\Samples\VB6\XMLLoadSave\Form1.frm (on 32-bit Windows versions).

VERSION 5.00
Object = "{04048830-2BE4-4868-8CDC-B8E6FC7815C5}#7.5#0"; "SftTree_IX86_U_80.ocx"
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Form1"
   ClientHeight    =   6000
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   6435
   BeginProperty Font 
      Name            =   "Microsoft Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6000
   ScaleWidth      =   6435
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin SftTreeLib80.SftTree SftTree1 
      Height          =   5055
      Left            =   120
      TabIndex        =   0
      Top             =   840
      Width           =   4935
      PropVer         =   50
      xcx             =   8705
      xcy             =   8916
      PropFile        =   ""
      PropDesignTime  =   1
      DeletePropFile  =   0
      IntVal          =   55
      xBfStyle1       =   63252554
      xBfStyle2       =   -1062647745
      xBfStyle3       =   -1109118987
      xBfStyle4       =   1109118987
      FlatProperties  =   0
      Appearance      =   1
      AutoRespond     =   1
      BackgroundStyle =   0
      BackgroundX     =   0
      BackgroundY     =   0
      BorderStyle     =   0
      ButtonStyle     =   2
      CellEventHandling=   0
      CellEditStyle   =   0
      CellEditLimit   =   0
      ColumnCount     =   3
      CopyItemDataString=   1
      CustomCode      =   0
      DragImage       =   0
      DragMethod      =   1
      DragType        =   3
      Enabled         =   1
      HandleReturn    =   1
      MousePointer    =   0
      LeftButtonOnly  =   1
      LeftItemClickOnly=   1
      OLEDropMode     =   0
      RightToLeft     =   0
      UseThemes       =   -1  'True
      Scrollbars      =   3
      ScrollbarStyle  =   0
      ShowTruncated   =   1
      VAlignStyle     =   0
      VirtualMode     =   0
      WebLicense      =   ""
      BeginProperty ItemEditFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty Columns {C449490E-B885-4CD1-9989-086D42C2F612} 
         InheritBgColor  =   1
         OpenEnded       =   1
         OpenEnded2      =   1
      EndProperty
      BeginProperty Headers {C4494906-B885-4CD1-9989-086D42C2F612} 
         Appearance      =   1
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         GrayedColor     =   -2147483631
         HilightColor    =   -2147483628
         Multiline       =   1
         ShadowColor     =   -2147483632
         Reorderable     =   1
         Resizable       =   1
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Microsoft Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      EndProperty
      BeginProperty Items {C449490C-B885-4CD1-9989-086D42C2F612} 
         AutoExpandDragDrop=   1
         AutoExpandHover =   0
         BackColor       =   -2147483643
         BackColorOdd    =   -2147483643
         CalcLimit       =   0
         CalcVisibleOnly =   0
         Cell3D          =   0
         CharSearchColumn=   -1
         CharSearchMode  =   1
         DropHighlightColor=   -2147483635
         DropHighlightStyle=   1
         EditNoFocusStyle=   2
         FlybyHighlight  =   1
         ForeColor       =   -2147483640
         ForeColorOdd    =   -2147483640
         GrayedColor     =   -2147483631
         GridHorizontalColor=   -1
         GridStyle       =   0
         GridVerticalColor=   -1
         HilightColor    =   -2147483628
         HorizontalExtentPix=   0
         HorizontalExtent2Pix=   0
         HorizontalOffsetPix=   0
         HorizontalOffset2Pix=   0
         Indentation     =   -1
         ItemImageAlign  =   1
         Lines           =   1
         MaxHeightPix    =   0
         MinHeightPix    =   0
         MultiSelect     =   0
         NoFocusStyle    =   0
         NoSelection     =   0
         RubberbandSelection=   1
         SelectBackColor =   -2147483635
         SelectBackColorNoFocus=   -2147483633
         SelectForeColor =   -2147483634
         SelectForeColorNoFocus=   -2147483630
         ShadowColor     =   -2147483632
         Style           =   0
         ScrollTips      =   1
         SelectionArea   =   1
         SelectStyle     =   2
         ShowFocusRectangle=   1
         ToolTipAlways   =   0
         ToolTipBackColor=   -1
         ToolTipForeColor=   -1
         ToolTipsUseEntireCell=   0
         TopIndex        =   0
         TreeLineColor   =   -2147483631
         TreeLineGrayedColor=   -2147483631
         TreeLineStyle   =   2
         UpdateCurrentExpandCollapse=   0
      EndProperty
      BeginProperty RowColumnHeader {C4494912-B885-4CD1-9989-086D42C2F612} 
         Appearance      =   1
         ButtonDown      =   0
         RemainUp        =   1
         Enabled         =   1
         ImageHAlign     =   0
         ImageVAlign     =   0
         TextHAlign      =   0
         TextVAlign      =   0
         Text            =   ""
         ForeColor       =   -2147483630
         BackColor       =   -2147483633
         HilightColor    =   -2147483628
         ShadowColor     =   -2147483632
         GrayedColor     =   -2147483631
      EndProperty
      BeginProperty RowHeaders {C4494914-B885-4CD1-9989-086D42C2F612} 
         Appearance      =   3
         RemainUp        =   1
         Enabled         =   1
         Lines           =   1
         TextHAlign      =   0
         TextVAlign      =   0
         Object.Width           =   40
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         GrayedColor     =   -2147483631
         HilightColor    =   -2147483628
         ShadowColor     =   -2147483632
         SelectBackColor =   -2147483633
         SelectForeColor =   -2147483630
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Microsoft Sans Serif"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
      EndProperty
      BeginProperty Splitter {C449491A-B885-4CD1-9989-086D42C2F612} 
         SplitColumn     =   0
         Object.Visible         =   0
         OffsetPix       =   0
         WidthPix        =   7
      EndProperty
      BeginProperty Column(0) {C4494908-B885-4CD1-9989-086D42C2F612} 
         BackColor       =   -1
         CellHAlign      =   0
         CellMultiline   =   0
         CellVAlign      =   0
         CellWordWrap    =   0
         ForeColor       =   -1
         Merge           =   0
         MergeInto       =   0
         MinWidth        =   0
         SelectBackColor =   -1
         SelectForeColor =   -1
         ToolTip         =   1
         Object.Width           =   100
         RealPos         =   0
         DispPos         =   0
      EndProperty
      BeginProperty Header(0) {C449490A-B885-4CD1-9989-086D42C2F612} 
         Enabled         =   1
         KeepPosition    =   0
         Locked          =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         RemainUp        =   0
         Text            =   "Title1"
         TextHAlign      =   0
         TextVAlign      =   0
      EndProperty
      BeginProperty Column(1) {C4494908-B885-4CD1-9989-086D42C2F612} 
         BackColor       =   -1
         CellHAlign      =   0
         CellMultiline   =   0
         CellVAlign      =   0
         CellWordWrap    =   0
         ForeColor       =   -1
         Merge           =   0
         MergeInto       =   0
         MinWidth        =   0
         SelectBackColor =   -1
         SelectForeColor =   -1
         ToolTip         =   1
         Object.Width           =   100
         RealPos         =   1
         DispPos         =   1
      EndProperty
      BeginProperty Header(1) {C449490A-B885-4CD1-9989-086D42C2F612} 
         Enabled         =   1
         KeepPosition    =   0
         Locked          =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         RemainUp        =   0
         Text            =   "Title2"
         TextHAlign      =   0
         TextVAlign      =   0
      EndProperty
      BeginProperty Column(2) {C4494908-B885-4CD1-9989-086D42C2F612} 
         BackColor       =   -1
         CellHAlign      =   0
         CellMultiline   =   0
         CellVAlign      =   0
         CellWordWrap    =   0
         ForeColor       =   -1
         Merge           =   0
         MergeInto       =   0
         MinWidth        =   0
         SelectBackColor =   -1
         SelectForeColor =   -1
         ToolTip         =   1
         Object.Width           =   100
         RealPos         =   2
         DispPos         =   2
      EndProperty
      BeginProperty Header(2) {C449490A-B885-4CD1-9989-086D42C2F612} 
         Enabled         =   1
         KeepPosition    =   0
         Locked          =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         RemainUp        =   0
         Text            =   "Title3"
         TextHAlign      =   0
         TextVAlign      =   0
      EndProperty
      SavedItemCount  =   6
      SavedColumnCount=   3
      BeginProperty Item(0) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   0
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   -1  'True
         Expandable      =   -1  'True
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Item(1) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   1
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   0   'False
         Expandable      =   0   'False
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Item(2) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   0
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   -1  'True
         Expandable      =   -1  'True
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Item(3) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   1
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   -1  'True
         Expandable      =   -1  'True
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Item(4) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   2
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   0   'False
         Expandable      =   0   'False
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Item(5) {C4494910-B885-4CD1-9989-086D42C2F612} 
         Data            =   0
         DataFloat       =   0
         DataString      =   ""
         EditIgnore      =   0   'False
         Enabled         =   -1  'True
         HideExpandCollapseButton=   0   'False
         Ignore          =   0   'False
         Level           =   0
         MaxHeightPix    =   0
         MinHeightPix    =   0
         Selected        =   0   'False
         Expanded        =   0   'False
         Expandable      =   0   'False
         Text            =   ""
         TextHAlign      =   -1
         TextVAlign      =   -1
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BeginProperty Cell(0) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "New Item, Cell 0"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(1) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 1"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
         BeginProperty Cell(2) {C4494916-B885-4CD1-9989-086D42C2F612} 
            Data            =   0
            DataString      =   ""
            EditIgnore      =   0   'False
            Ignore          =   0   'False
            Text            =   "Cell 2"
            TextHAlign      =   -1
            TextVAlign      =   -1
            BackColor       =   -1
            ForeColor       =   -1
            SelectBackColor =   -1
            SelectForeColor =   -1
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Microsoft Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
   Begin VB.CommandButton PopulateCommand 
      Caption         =   "Populate"
      Height          =   375
      Left            =   5160
      TabIndex        =   8
      Top             =   4320
      Width           =   1095
   End
   Begin VB.CommandButton ClearButton 
      Caption         =   "Clear"
      Height          =   375
      Left            =   5160
      TabIndex        =   7
      Top             =   4800
      Width           =   1095
   End
   Begin VB.CommandButton SaveNestedButton 
      Caption         =   "Save (Nested)"
      Height          =   495
      Left            =   5160
      TabIndex        =   6
      Top             =   2400
      Width           =   1095
   End
   Begin VB.CommandButton LoadButton 
      Caption         =   "Load"
      Height          =   375
      Left            =   5160
      TabIndex        =   3
      Top             =   3120
      Width           =   1095
   End
   Begin VB.CommandButton SaveFlatButton 
      Caption         =   "Save (Flat)"
      Height          =   495
      Left            =   5160
      TabIndex        =   2
      Top             =   1800
      Width           =   1095
   End
   Begin VB.CommandButton CloseButton 
      Cancel          =   -1  'True
      Caption         =   "Close"
      Height          =   375
      Left            =   5160
      TabIndex        =   1
      Top             =   840
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "XML Load/Save Sample"
      BeginProperty Font 
         Name            =   "Microsoft Sans Serif"
         Size            =   9.75
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   120
      TabIndex        =   5
      Top             =   120
      Width           =   4935
   End
   Begin VB.Label Label1 
      Caption         =   "This sample loads/saves file C:\SftTreeTest.xml"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   480
      Width           =   4935
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Const g_FileName As String = "C:\SftTreeTest.xml"

Private Sub ClearButton_Click()
    SftTree1.Items.Clear
End Sub

Private Sub CloseButton_Click()
    End
End Sub

Private Sub PopulateCommand_Click()
    ' Populate the tree control with sample data
    SftTree1.BulkUpdate = True
    SftTree1.Items.Clear
    
    Dim itemIndex As Long
    
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Item(itemIndex).Level = 1
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Item(itemIndex).Level = 1
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Item(itemIndex).Level = 2
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    itemIndex = SftTree1.Items.Add("New Item, Cell 0")
     SftTree1.Cell(itemIndex, 1).Text = "Cell 1"
     SftTree1.Cell(itemIndex, 2).Text = "Cell 2"
    
    SftTree1.BulkUpdate = False
End Sub

Private Sub SaveFlatButton_Click()
    Dim xmlDoc As New DOMDocument30
    Dim RootElementNode As IXMLDOMElement
    Dim ItemsElementNode As IXMLDOMElement
    
    Set ItemsElementNode = xmlDoc.createElement("Items")
    Set RootElementNode = xmlDoc.appendChild(ItemsElementNode)
    
    ' loop through all items and save relevant item information
    ' as a flat list
    Dim i As Integer
    For i = 0 To SftTree1.Items.Count - 1
        Dim Item As SftTreeItem
        Dim ItemElementNode As IXMLDOMElement
        
        Set Item = SftTree1.Item(i)
        
        Dim childNode
        Set childNode = AddItemInformation(xmlDoc, Item, False)
        
        RootElementNode.appendChild childNode
    Next
    
    ' save xml
    xmlDoc.save g_FileName
End Sub

Private Sub SaveNestedButton_Click()
    Dim xmlDoc As New DOMDocument30
    Dim RootElementNode As IXMLDOMElement
    Dim ItemsElementNode As IXMLDOMElement
    
    Set ItemsElementNode = xmlDoc.createElement("Items")
    Set RootElementNode = xmlDoc.appendChild(ItemsElementNode)
    
    ' visit all items and save relevant item information
    Dim itemIndex As Long
    itemIndex = SftTree1.Items.FirstShown
    
    Do While itemIndex >= 0
    
        Set Item = SftTree1.Item(itemIndex)
        
        Dim childNode
        Set childNode = AddItemInformation(xmlDoc, Item, True)
        
        RootElementNode.appendChild childNode
        
        itemIndex = Item.nextSibling
    Loop

    ' save xml
    xmlDoc.save g_FileName
End Sub

Function AddItemInformation(ByVal xmlDoc As DOMDocument30, ByVal Item As SftTreeItem, Nested As Boolean)
    Set ItemElementNode = xmlDoc.createElement("Item")

    ' save some of the item properties that are important to your application
    ItemElementNode.setAttribute "Data", Item.Data
    ItemElementNode.setAttribute "DataString", Item.DataString
    If Not Nested Then
        ItemElementNode.setAttribute "Level", Item.Level
    End If

    ' loop through all cells and save relevant information
    Dim c As Integer
    For c = 0 To SftTree1.ColumnsObj.Count - 1
        Dim Cell As SftTreeCell
        Dim CellElementNode As IXMLDOMElement
        
        Set Cell = Item.Cell(c)
        Set CellElementNode = xmlDoc.createElement("Cell")
        
        ' save some of the cell properties that are important to your application
        CellElementNode.setAttribute "Text", Cell.Text
    
        ItemElementNode.appendChild CellElementNode
    Next

    ' visit all child items (if nested)
    If Nested Then
        Dim itemIndex As Long
        itemIndex = Item.FirstDependent
        
        Do While itemIndex >= 0
        
            Set Item = SftTree1.Item(itemIndex)
            
            Dim childNode
            Set childNode = AddItemInformation(xmlDoc, Item, Nested)
            
            ItemElementNode.appendChild childNode
            
            itemIndex = Item.nextSibling
        Loop
    End If
    Set AddItemInformation = ItemElementNode
End Function
        
Private Sub LoadButton_Click()
    ' this can load flat or nested xml
    ' flat xml uses the "Level" property, nested xml rebuilds the tree using the hierarchy
    Dim xmlDoc As DOMDocument30
    Set xmlDoc = New DOMDocument30
    If Not xmlDoc.Load(g_FileName) Then
        MsgBox "File " & g_FileName & " could not be loaded."
        Exit Sub
    End If
    
    SftTree1.BulkUpdate = True
    
    SftTree1.Items.Clear
    
    Dim List As IXMLDOMNodeList
    Set List = xmlDoc.selectNodes("/Items/Item")
    
    Dim itemElement As IXMLDOMElement
    For Each itemElement In List
        AddOneItem itemElement, 0
    Next

    SftTree1.BulkUpdate = False
End Sub
    
Sub AddOneItem(itemElement As IXMLDOMElement, Level As Integer)

    ' add an item
    Dim itemIndex As Long
    itemIndex = SftTree1.Items.Add("")

    ' restore all item properties that we saved
    Dim Item As SftTreeItem
    Set Item = SftTree1.Item(itemIndex)
    Item.Data = itemElement.getAttribute("Data")
    Item.DataString = itemElement.getAttribute("DataString")
    If itemElement.getAttribute("Level") <> "" Then
        ' we saved the level (flat list), so restore it now
        Item.Level = itemElement.getAttribute("Level")
    Else
        Item.Level = Level
    End If
    
    ' restore all cell properties that we saved
    Dim CellList As IXMLDOMNodeList
    Set CellList = itemElement.selectNodes("Cell")
    
    Dim cellElement As IXMLDOMElement
    Dim c As Integer
    c = 0
    For Each cellElement In CellList
        Dim Cell As SftTreeCell
        Set Cell = Item.Cell(c)
        
        Cell.Text = cellElement.getAttribute("Text")
        c = c + 1
    Next
    
    ' check if there are saved child items (hierarchy)
    Dim List As IXMLDOMNodeList
    Set List = itemElement.selectNodes("Item")
    
    For Each itemElement In List
        AddOneItem itemElement, Level + 1
    Next
End Sub

Last Updated 05/24/2026 - (email)
© 2026 Softel vdm, Inc.