HeaderPane
Main
Hide

SftTree/OCX 8.0 - ActiveX Tree Control

Share Link
Print

DragDrop Sample (VB6)

This sample illustrates drag & drop.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTree OCX 8.0\Samples\VB6\DragDrop\Form1.frm or C:\Program Files\Softelvdm\SftTree OCX 8.0\Samples\VB6\DragDrop\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         =   "Softel vdm, Inc. - DragDrop Sample"
   ClientHeight    =   5955
   ClientLeft      =   900
   ClientTop       =   1230
   ClientWidth     =   6705
   BeginProperty Font 
      Name            =   "Microsoft Sans Serif"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   PaletteMode     =   1  'UseZOrder
   ScaleHeight     =   5955
   ScaleWidth      =   6705
   Begin SftTreeLib80.SftTree SftTree1 
      Height          =   4932
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3852
      PropVer         =   75
      xcx             =   6800
      xcy             =   8705
      PropFile        =   ""
      PropDesignTime  =   1
      DeletePropFile  =   0
      IntVal          =   55
      xBfStyle1       =   64044624
      xBfStyle2       =   2117790927
      xBfStyle3       =   2070523519
      xBfStyle4       =   -2070523519
      FlatProperties  =   0
      Appearance      =   1
      AutoRespond     =   1
      BackgroundStyle =   0
      BackgroundX     =   0
      BackgroundY     =   0
      BorderStyle     =   0
      ButtonStyle     =   2
      CellEventHandling=   0
      CellEditStyle   =   0
      CellEditLimit   =   0
      ColumnCount     =   1
      CopyItemDataString=   0
      CustomCode      =   0
      DragImage       =   -842150451
      DragMethod      =   3
      DragType        =   7
      Enabled         =   1
      HandleReturn    =   -842150451
      MouseIcon       =   "Form1.frx":000C
      MousePointer    =   0
      LeftButtonOnly  =   -1
      LeftItemClickOnly=   0
      OLEDropMode     =   1
      RightToLeft     =   0
      UseThemes       =   -1  'True
      Scrollbars      =   3
      ScrollbarStyle  =   0
      ShowTruncated   =   -1
      VAlignStyle     =   0
      VirtualMode     =   0
      WebLicense      =   ""
      SmoothScroll    =   1
      ButtonAppearance=   8
      MouseOverTransitionEffect=   0
      EdgeVerticalColor=   -1
      EdgeHorizontalColor=   -1
      BeginProperty ItemEditFont {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
      BeginProperty Columns {9EBAA93E-293D-44FA-9989-08F078763A1F} 
         InheritBgColor  =   0
         OpenEnded       =   1
         OpenEnded2      =   1
      EndProperty
      BeginProperty Headers {9EBAA936-293D-44FA-9989-08F078763A1F} 
         Appearance      =   1
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         GrayedColor     =   -2147483631
         HilightColor    =   -2147483628
         Multiline       =   0
         ShadowColor     =   -2147483632
         Reorderable     =   0
         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
         SortIndicators  =   0
      EndProperty
      BeginProperty Footers {9EBAA956-293D-44FA-9989-08F078763A1F} 
         Appearance      =   0
         BackColor       =   -2147483633
         ForeColor       =   -2147483630
         GrayedColor     =   -2147483631
         HilightColor    =   -2147483628
         Multiline       =   1
         ShadowColor     =   -2147483632
         Reorderable     =   1
         Resizable       =   1
      EndProperty
      BeginProperty Items {9EBAA93C-293D-44FA-9989-08F078763A1F} 
         AutoExpandDragDrop=   1
         AutoExpandHover =   0
         BackColor       =   -2147483643
         BackColorOdd    =   -2147483643
         CalcLimit       =   500
         CalcVisibleOnly =   0
         Cell3D          =   0
         CharSearchColumn=   0
         CharSearchMode  =   1
         DropHighlightColor=   -2147483635
         DropHighlightStyle=   1
         EditNoFocusStyle=   2
         FlybyHighlight  =   1
         ForeColor       =   -2147483640
         ForeColorOdd    =   -2147483640
         GrayedColor     =   -2147483631
         GridHorizontalColor=   -2147483632
         GridStyle       =   0
         GridVerticalColor=   -2147483632
         HilightColor    =   -2147483628
         HorizontalExtentPix=   0
         HorizontalExtent2Pix=   0
         HorizontalOffsetPix=   0
         HorizontalOffset2Pix=   0
         Indentation     =   -1
         ItemImageAlign  =   1
         Lines           =   1
         MaxHeightPix    =   0
         MinHeightPix    =   0
         MultiSelect     =   0
         NoFocusStyle    =   1
         NoSelection     =   0
         RubberbandSelection=   1
         SelectBackColor =   -2147483635
         SelectBackColorNoFocus=   -2147483635
         SelectForeColor =   -2147483634
         SelectForeColorNoFocus=   -2147483634
         ShadowColor     =   -2147483632
         Style           =   0
         ScrollTips      =   0
         SelectionArea   =   0
         SelectStyle     =   2
         ShowFocusRectangle=   1
         ToolTipAlways   =   0
         ToolTipBackColor=   -1
         ToolTipForeColor=   -1
         ToolTipsUseEntireCell=   1
         TopIndex        =   0
         TreeLineColor   =   -2147483632
         TreeLineGrayedColor=   -2147483631
         TreeLineStyle   =   3
         UpdateCurrentExpandCollapse=   0
         OutlineStyle    =   1
         SelectOutlineBorderColor=   -1
         SelectInnerBorderColor=   -1
         SelectInnerFill1=   -1
         SelectInnerFill2=   -1
         SelectHotOutlineBorderColor=   -1
         SelectHotInnerBorderColor=   -1
         SelectHotInnerFill1=   -1
         SelectHotInnerFill2=   -1
         SelectNoFocusOutlineBorderColor=   -1
         SelectNoFocusInnerBorderColor=   -1
         SelectNoFocusInnerFill1=   -1
         SelectNoFocusInnerFill2=   -1
         HotOutlineBorderColor=   -1
         HotInnerBorderColor=   -1
         HotInnerFill1   =   -1
         HotInnerFill2   =   -1
         DropTargetOutlineBorderColor=   -1
         DropTargetInnerBorderColor=   -1
         DropTargetInnerFill1=   -1
         DropTargetInnerFill2=   -1
         DisabledItemsSelectable=   1
         AutoExpandDragDropInterval=   1200
         AutoExpandHoverInterval=   1200
         ToolTipIntervalOn=   200
         ToolTipIntervalOff=   100
         BeginProperty ItemImageExpandable {980702E2-0AB6-41B1-9B85-F8755A697255} 
            Object.Height          =   0
            Object.Width           =   0
            Picture         =   "Form1.frx":0028
            Appearance      =   -1
            FrameColor      =   -1
            SampleColor     =   -1
         EndProperty
         BeginProperty ItemImageExpanded {980702E2-0AB6-41B1-9B85-F8755A697255} 
            Object.Height          =   0
            Object.Width           =   0
            Picture         =   "Form1.frx":013A
            Appearance      =   -1
            FrameColor      =   -1
            SampleColor     =   -1
         EndProperty
         BeginProperty ItemImageLeaf {980702E2-0AB6-41B1-9B85-F8755A697255} 
            Object.Height          =   0
            Object.Width           =   0
            Picture         =   "Form1.frx":024C
            Appearance      =   -1
            FrameColor      =   -1
            SampleColor     =   -1
         EndProperty
      EndProperty
      BeginProperty RowColumnHeader {9EBAA942-293D-44FA-9989-08F078763A1F} 
         Appearance      =   0
         ButtonDown      =   0
         RemainUp        =   1
         Enabled         =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         TextHAlign      =   0
         TextVAlign      =   0
         Text            =   ""
         ForeColor       =   -2147483630
         BackColor       =   -2147483633
         HilightColor    =   -2147483628
         ShadowColor     =   -2147483632
         GrayedColor     =   -2147483631
         OverrideTheme   =   0
      EndProperty
      BeginProperty RowColumnFooter {9EBAA95A-293D-44FA-9989-08F078763A1F} 
         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
         OverrideTheme   =   0
      EndProperty
      BeginProperty RowHeaders {9EBAA944-293D-44FA-9989-08F078763A1F} 
         Appearance      =   0
         RemainUp        =   1
         Enabled         =   1
         Lines           =   1
         TextHAlign      =   0
         TextVAlign      =   0
         Object.Width           =   0
         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 {9EBAA94A-293D-44FA-9989-08F078763A1F} 
         SplitColumn     =   0
         Object.Visible         =   0
         OffsetPix       =   0
         WidthPix        =   7
      EndProperty
      BeginProperty Column(0) {9EBAA938-293D-44FA-9989-08F078763A1F} 
         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           =   20
         RealPos         =   0
         DispPos         =   0
         BackColorEnd    =   -1
         SelectBackColorEnd=   -1
         ProgressColor   =   -1
         ProgressColorEnd=   -1
         BackColorOrientation=   0
         ProgressColor   =   -1
         ProgressColorEnd=   -1
         ProgressColorOrientation=   0
         ProgressStyle   =   0
      EndProperty
      BeginProperty Header(0) {9EBAA93A-293D-44FA-9989-08F078763A1F} 
         Enabled         =   1
         KeepPosition    =   0
         Locked          =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         RemainUp        =   1
         Text            =   "Sample Items"
         TextHAlign      =   0
         TextVAlign      =   0
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BackColorDisabled=   -1
         ForeColorDisabled=   -1
         OverrideTheme   =   0
         Button          =   0
      EndProperty
      BeginProperty Footer(0) {9EBAA958-293D-44FA-9989-08F078763A1F} 
         Enabled         =   1
         KeepPosition    =   0
         ImageHAlign     =   0
         ImageVAlign     =   0
         RemainUp        =   0
         Text            =   ""
         TextHAlign      =   0
         TextVAlign      =   0
         BackColor       =   -1
         ForeColor       =   -1
         SelectBackColor =   -1
         SelectForeColor =   -1
         BackColorDisabled=   -1
         ForeColorDisabled=   -1
         OverrideTheme   =   0
         Button          =   0
      EndProperty
      SavedItemCount  =   0
      SavedColumnCount=   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
   End
   Begin VB.PictureBox Picture2 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   252
      Left            =   4560
      OLEDragMode     =   1  'Automatic
      Picture         =   "Form1.frx":035E
      ScaleHeight     =   195
      ScaleWidth      =   315
      TabIndex        =   6
      Top             =   2400
      Width           =   372
   End
   Begin VB.TextBox Text1 
      Height          =   372
      Left            =   5160
      OLEDragMode     =   1  'Automatic
      TabIndex        =   4
      Text            =   "Text1"
      Top             =   2400
      Width           =   1332
   End
   Begin VB.PictureBox Picture1 
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   252
      Left            =   4080
      OLEDragMode     =   1  'Automatic
      Picture         =   "Form1.frx":0440
      ScaleHeight     =   195
      ScaleWidth      =   315
      TabIndex        =   3
      Top             =   2400
      Width           =   372
   End
   Begin VB.CommandButton Command1 
      Cancel          =   -1  'True
      Caption         =   "Close"
      Height          =   375
      Left            =   5520
      TabIndex        =   1
      Top             =   120
      Width           =   1092
   End
   Begin VB.Label Label5 
      Caption         =   $"Form1.frx":0522
      Height          =   732
      Left            =   120
      TabIndex        =   10
      Top             =   5160
      Width           =   6492
   End
   Begin VB.Label DropTarget 
      BorderStyle     =   1  'Fixed Single
      Height          =   375
      Left            =   4440
      OLEDropMode     =   1  'Manual
      TabIndex        =   9
      Top             =   4440
      Width           =   2175
   End
   Begin VB.Image DropTargetPic 
      Height          =   375
      Left            =   4080
      Top             =   4440
      Width           =   375
   End
   Begin VB.Label Label4 
      Caption         =   "Drag items from the tree control to the drop target below.  In this example, only one item is shown."
      Height          =   735
      Left            =   4080
      TabIndex        =   8
      Top             =   3600
      Width           =   2415
   End
   Begin VB.Label Label3 
      Caption         =   "Drop Target"
      BeginProperty Font 
         Name            =   "Microsoft Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4080
      TabIndex        =   7
      Top             =   3120
      Width           =   2415
   End
   Begin VB.Label Label2 
      Caption         =   "Drag Sources"
      BeginProperty Font 
         Name            =   "Microsoft Sans Serif"
         Size            =   12
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   4080
      TabIndex        =   5
      Top             =   720
      Width           =   2415
   End
   Begin VB.Label Label1 
      Caption         =   $"Form1.frx":0603
      Height          =   1095
      Left            =   4080
      TabIndex        =   2
      Top             =   1200
      Width           =   2415
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private Sub Command1_Click()
    End
End Sub

Private Sub Form_Load()
    Dim i As Integer
    With SftTree1
        .Items.Add "Item 0"
         i = .Items.Add("Item 1")
         .Item(i).Level = 1
        i = .Items.Add("Item 2")
         .Item(i).Level = 2
        i = .Items.Add("Item 3")
         .Item(i).Level = 1
    End With
End Sub

Private Sub DropTarget_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    If Data.GetFormat(vbCFText) Then
        DropTarget.Caption = Data.GetData(vbCFText)
    End If
    If Data.GetFormat(vbCFDIB) Then
        Set DropTargetPic.Picture = Data.GetData(vbCFDIB)
    End If
End Sub


Private Sub SftTree1_OLEStartDrag(Data As SftTreeLib80.DataObject, AllowedEffects As Long)
    Dim curr As Integer
    curr = SftTree1.Items.Current
    ' cell text
    Data.SetData SftTree1.Cell(curr, 0).Text, vbCFText
    ' item picture
    If SftTree1.Item(curr).Image.Type = sftTypeIDispatch Then
        Data.SetData SftTree1.Item(curr).Image.Picture, vbCFDIB
    Else
        If SftTree1.Item(curr).Expanded Then
            Data.SetData SftTree1.Items.ItemImageExpanded.Picture, vbCFDIB
        ElseIf SftTree1.Item(curr).DependentAllCount > 0 Then
            Data.SetData SftTree1.Items.ItemImageExpandable.Picture, vbCFDIB
        Else
            Data.SetData SftTree1.Items.ItemImageLeaf.Picture, vbCFDIB
        End If
    End If
End Sub

Private Sub SftTree1_OLEDragDrop(Data As SftTreeLib80.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim insertAt As Integer
    Dim str As String
    Dim lvl As Integer, newItem As Integer
    Dim horzExtent As Single, col0Width As Single
    
    ' get horizontal extent and width of column 0
    horzExtent = SftTree1.Items.HorizontalExtent
    col0Width = SftTree1.Column(0).Width
    
    insertAt = SftTree1.Items.DropHighlight
    If insertAt < 0 Then Exit Sub
    
    If Data.GetFormat(vbCFText) Then
        lvl = SftTree1.Item(insertAt).Level
        str = Data.GetData(vbCFText)
        newItem = SftTree1.Items.Insert(insertAt + 1, str)
        SftTree1.Item(newItem).Level = lvl + 1
    ElseIf Data.GetFormat(vbCFDIB) Then
        Set SftTree1.Cell(insertAt, 0).Image.Picture = Data.GetData(vbCFDIB)
        SftTree1.Cell(insertAt, 0).ImageHAlign = halignSftTreeRight
    ElseIf Data.GetFormat(vbCFFiles) Then
        SftTree1.BulkUpdate = True
        lvl = SftTree1.Item(insertAt).Level
        newItem = insertAt + 1
        For i = Data.Files.Count To 1 Step -1
            newItem = SftTree1.Items.Insert(newItem, Data.Files.Item(i))
            SftTree1.Item(newItem).Level = lvl + 1
        Next
        SftTree1.BulkUpdate = False
    End If
    
    ' make horizontal extent and width of column 0 wider than previous
    ' setting, but never smaller
    SftTree1.ColumnsObj.MakeOptimal
    SftTree1.Items.RecalcHorizontalExtent
    
    If horzExtent > SftTree1.Items.HorizontalExtent Then
        SftTree1.Items.HorizontalExtent = horzExtent
    End If
    If col0Width > SftTree1.Column(0).Width Then
        SftTree1.Column(0).Width = col0Width
    End If
End Sub

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