Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag-drop for dummies 1

Status
Not open for further replies.

ghardenb

Programmer
Oct 24, 2004
28
US
Would someone please post an example of code for dragging a list item from one listbox to another?
 
For the example below, the starting listview is lvwDefaultProcess and dropping listview is lvwProcess;

Firstly create two variables in the general declarations area of the form;

Private itmProcess As ListItem
Private blnProcessAdd As Boolean

In the lvwDefaultProcess_OLEStartDrag event add;

blnProcessAdd = True
Set itmProcess = lvwDefaultProcess.SelectedItem

And in the lvwProcess_OLEDragDrop event;

Dim itmNewProcess As ListItem

On Error GoTo Exit_Routine

If Not itmProcess Is Nothing Then
If blnProcessAdd Then
Set itmNewProcess = lvwProcess.ListItems.Add(, itmProcess.Key, itmProcess.Text)
itmNewProcess.SubItems(1) = lvwProcess.ListItems.Count
blnProcessAdd = False
End If
End If

Exit_Routine:
Set itmProcess = Nothing
Set itmNewProcess = Nothing
 
Add 2 list boxes to your form

on list box1 set OLEDragMode to auto and set OLEDropMode to None

Second listb SetOLEDropMode to Manual

Add the following code in the OLEDragDrop event fot List 2

Private Sub List2_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer

List2.AddItem Data.GetData(1)
List1.RemoveItem (List1.ListIndex)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top