Hide

SftBox/OCX 5.0 - Combo Box Control

Display
Print

DragDrop Sample (VB.NET)

This sample illustrates drag & drop.

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

Private Sub closeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeButton.Click
    Application.Exit()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.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

Private Sub comboSource_DragStarting(ByVal sender As Object, ByVal e As AxSftBoxLib50._ISftBoxEvents_DragStartingEvent) Handles comboSource.DragStarting
    comboSource.OLEDrag()
End Sub

Private Sub comboSource_OLEStartDrag(ByVal sender As Object, ByVal e As AxSftBoxLib50._ISftBoxEvents_OLEStartDragEvent) Handles comboSource.OLEStartDrag
    e.allowedEffects = vbDropEffectCopy Or vbDropEffectMove
    Dim textData As String = comboSource.get_Cell(comboSource.Items.Selection, 0).Text
    e.data.SetData(textData, SftOLEClipboardConstants.sftCFText)
End Sub

Private Sub comboTarget_OLEDragOver(ByVal sender As Object, ByVal e As AxSftBoxLib50._ISftBoxEvents_OLEDragOverEvent) Handles comboTarget.OLEDragOver
    If e.state = SftBoxOLEDragOverConstants.enterSftBox Then
        ' Show the drop down portion
        comboTarget.DropDown.Dropped = True
    ElseIf e.state = SftBoxOLEDragOverConstants.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(ByVal sender As Object, ByVal e As AxSftBoxLib50._ISftBoxEvents_OLEDragDropEvent) Handles comboTarget.OLEDragDrop
    If e.data.GetFormat(SftOLEClipboardConstants.sftCFText) Then
        Dim itemIndex As Integer
        itemIndex = comboTarget.Items.Insert(e.data.GetData(SftOLEClipboardConstants.sftCFText), comboTarget.Items.DropIndex)
        comboTarget.Items.Selection = itemIndex
    End If
    If e.data.GetFormat(SftOLEClipboardConstants.sftCFBitmap) Then
        Dim itemIndex As Integer
        itemIndex = comboTarget.Items.Insert("A Bitmap", comboTarget.Items.DropIndex)
        Dim o As Object = e.data.GetData(SftOLEClipboardConstants.sftCFBitmap)
        comboTarget.get_Item(itemIndex).Image.Picture = o 'as stdole.IPictureDisp
        comboTarget.Items.Selection = itemIndex
    End If
    If e.data.GetFormat(SftOLEClipboardConstants.sftCFFiles) Then
        Dim itemIndex As Integer = -1
        Dim toIndex As Integer = comboTarget.Items.DropIndex
        Dim s As String
        For Each s In e.data.Files
            itemIndex = comboTarget.Items.Insert(s, toIndex)
            toIndex = toIndex + 1
        Next
        comboTarget.Items.Selection = itemIndex
    End If
    comboTarget.Columns.MakeOptimal(0)
    comboTarget.Items.RecalcHorizontalExtent(0)
End Sub

Private Sub dragLabel_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dragLabel.MouseDown
    dragLabel.DoDragDrop(dragLabel.Text, DragDropEffects.Copy)
End Sub

Private Sub pictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pictureBox1.MouseDown
    dragLabel.DoDragDrop(pictureBox1.Image, DragDropEffects.Copy)
End Sub

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