Results 1 to 3 of 3

Thread: Drag Listview Item to listbox

  1. #1

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    Drag Listview Item to listbox

    Hi how can i allow the user to drag a item from a listview to a
    listbox and in the listbox a subitem is shown as items text

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    ... and in the listbox a subitem is shown as items text
    What exactly does this mean ???

  3. #3
    Hyperactive Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    506
    Amazing what you can learn in a quarter of an hour, I'd never done any OLE drag/drop before. Needs a listbox and a listview, no props changed.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.   Dim lvItem As ListItem
    5.   Set lvItem = ListView1.ListItems.Add(, , "weee")
    6.  
    7.   List1.OLEDropMode = ccOLEDropManual
    8.  
    9.   With ListView1
    10.     .OLEDragMode = ccOLEDragAutomatic
    11.  
    12.     .View = lvwReport
    13.     .FullRowSelect = True
    14.     Call .ColumnHeaders.Add(, , "bleh")
    15.     Call .ColumnHeaders.Add(, , "bleh2")
    16.   End With
    17.   lvItem.SubItems(1) = "hi"
    18. End Sub
    19.  
    20. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    21.   Dim sData As String
    22.   sData = Data.GetData(vbCFText)
    23.    
    24.   If Data.GetFormat(vbCFText) Then
    25.     Call List1.AddItem(sData)
    26.   End If
    27. End Sub
    28.  
    29. Private Sub ListView1_OLESetData(Data As MSComctlLib.DataObject, DataFormat As Integer)
    30.   'Just change the number below to send a different sub item
    31.   Call Data.SetData(ListView1.SelectedItem.SubItems(1))
    32. End Sub
    33.  
    34. 'The below procs should stop other programs from being _
    35.   able to drop onto the listbox.. in theory
    36.  
    37. Private Sub ListView1_OLECompleteDrag(Effect As Long)
    38.   List1.OLEDropMode = ccOLEDropNone
    39. End Sub
    40.  
    41. Private Sub ListView1_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)
    42.   List1.OLEDropMode = ccOLEDropManual
    43. End Sub

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