Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

DragDrop Sample (VB6)

This sample illustrates drag & drop.

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

Option Explicit

Private Sub ComboTarget_OLEDragOver(Data As SftBoxLib50.DataObject, TargetIndex As Long, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As SftBoxLib50.SftBoxOLEDragOverConstants)
    If State = enterSftBox Then
        ' Show the drop down portion
        ComboTarget.DropDown.Dropped = True
    ElseIf State = leaveSftBox Then
        ' Hide the drop down portion with a delay, in case the
        ' user is moving from/to the static or drop down portion
        ComboTarget.DropDown.RollUp 500  ' 1/2 second
    End If
End Sub

Private Sub ComboTarget_OLEDragDrop(Data As SftBoxLib50.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
    Dim ItemIndex As Long
    If Data.GetFormat(sftCFText) Then
        ItemIndex = ComboTarget.Items.Insert(Data.GetData(sftCFText), ComboTarget.Items.DropIndex)
        ComboTarget.Items.Selection = ItemIndex
    End If
    If Data.GetFormat(sftCFDIB) Then
        ItemIndex = ComboTarget.Items.Insert("A Bitmap", ComboTarget.Items.DropIndex)
        Set ComboTarget.Item(ItemIndex).Image.Picture = Data.GetData(sftCFDIB)
        ComboTarget.Items.Selection = ItemIndex
    End If
    If Data.GetFormat(sftCFFiles) Then
        Dim vData As Variant, ToIndex As Long
        ToIndex = ComboTarget.Items.DropIndex
        For Each vData In Data.Files
            ItemIndex = ComboTarget.Items.Insert(vData, ToIndex)
            ToIndex = ToIndex + 1
        Next
        ComboTarget.Items.Selection = ItemIndex
    End If
    ComboTarget.Columns.MakeOptimal 0
    ComboTarget.Items.RecalcHorizontalExtent 0
End Sub

Private Sub ComboSource_DragStarting(ByVal Part As SftBoxLib50.SftBoxPortionConstants, ByVal Button As Integer, ByVal Shift As Integer, ByVal xPos As Single, ByVal yPos As Single)
    ComboSource.OLEDrag
End Sub

Private Sub ComboSource_OLEStartDrag(Data As SftBoxLib50.DataObject, AllowedEffects As Long)
    AllowedEffects = vbDropEffectCopy Or vbDropEffectMove
    Data.SetData ComboSource.Cell(ComboSource.Items.Selection, 0).Text, sftCFText
End Sub

Private Sub Command1_Click()
    Unload Form1
End Sub

Private Sub Form_Load()
    ComboSource.Items.Add "An Item"
    ComboSource.Items.Add "Another Item"
    ComboSource.Items.Add "Last Item"
    ComboSource.Columns.MakeOptimal 0
    ComboSource.Items.RecalcHorizontalExtent 0

    ComboTarget.Items.Add "A Source Item"
    ComboTarget.Items.Add "Another Source Item"
    ComboTarget.Items.Add "Last Source Item"
    ComboTarget.Columns.MakeOptimal 0
    ComboTarget.Items.RecalcHorizontalExtent 0
End Sub

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.