CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Jan 2001
    Location
    Los Angeles, CA, United States
    Posts
    47

    Drag & Drop in ListView and PictureBox

    Hello Gurus!

    I'm wondering something about manual Drag & Drop in ListView.
    Source is ListView and Target is PictureBox.
    ListView has image items.
    What I would do is :
    There's an icon on each items of the ListView.
    Drag one item(icon) and drag on picture box, then the item of
    the listview is copied to the picturebox.

    Question is :
    1. How can extract one item in OLEStartDrag event?
    2. I would pass the file name to the target, then what format
    should I use? vbCFText? or vbCFFiles? or other format?

    Could anybody help me?

    P.S) If have some sample source code, can you let me refer to it?

  2. #2
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930
    1. How can extract one item in OLEStartDrag event?
    In various ways. You should fill the "Data" parameter during the ListView_OLEStartDrag event. You can store the name of object or other locate information where the Picture control could load the image from. You can also store the image of the ListView's item in Screen.MouseIcon (as you can see from description of the OLEGiveFeedback event). E.g.
    Code:
    Private Sub ListView1_OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)
      Effect = (vbDropEffectMove Or vbDropEffectCopy)
      Screen.MousePointer = vbCustom
      Set Screen.MouseIcon = ListView1.Icons.ListImages(ListView1.SelectedItem.Icon).Picture
      DefaultCursors = False
    End Sub
    ... And so on.

    2. I would pass the file name to the target, then what format should I use? vbCFText? or vbCFFiles? or other format?
    There are some methods to do this in ListView1_OLEStartDrag event.
    a) Filling real data
    Code:
    Private Sub ListView1_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
      AllowedEffects = (vbDropEffectMove Or vbDropEffectCopy)
    '
      Call Data.SetData("some_file", vbCFText)
      Call Data.SetData(, vbCFFiles)
          Call Data.Files.Add("some_file") ' ...
    End Sub
    b) Filling only the supported formats value and fill real data only in ListView1_OLESetData with required format.
    Code:
    Private Sub ListView1_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
      AllowedEffects = (vbDropEffectMove Or vbDropEffectCopy)
    '
      Call Data.Clear
      Call Data.SetData(, vbCFFiles)
      Call Data.SetData(, vbCFText) ' ...
    End Sub
    
    Private Sub ListView1_OLESetData(Data As MSComctlLib.DataObject, DataFormat As Integer)
      If DataFormat = vbCFFiles Then
          Call Data.Files.Add("some_file") ' ...
      ElseIf DataFormat = vbCFText Then
          Call Data.SetData("some_file", DataFormat)
      End If
    End Sub
    HTH
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured