Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.visual.basic    |    MS Visual Basic discussions, NOT dot-net    |    10,840 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 9,539 of 10,840    |
|    Rick Rothstein to Reid Nix    |
|    Re: ListBox Drag Items    |
|    03 Jun 05 20:34:59    |
      From: rickNOSPAMnews@NOSPAMcomcast.net              > I need some code to drag items in a list box either up or       > down along with not just the text but with the itemdata too.       > Can anyone hook me up?              This may not be as "visual" as you might be looking for (can't be sure       because you didn't say); but the ItemData moves with the item. Here is a       previous post of mine that shows a method for doing that.              Rick - MVP              Use this sample project as a guide. Put a ListBox in a new project       (leave its Name as the default of List1). Paste this code into the       Form's code window and Run the project.              ********START PASTE********       Dim DragIndex As Long              Private Sub Form_Load()        ' Just load the ListBox up with something        With List1        For X = 0 To 10        .AddItem "Item #" & CStr(X + 1)        Next        End With       End Sub              Private Sub List1_MouseDown(Button As Integer, _        Shift As Integer, X As Single, Y As Single)        With List1        DragIndex = .ListIndex        End With       End Sub              Private Sub List1_MouseUp(Button As Integer, _        Shift As Integer, X As Single, Y As Single)        With List1        If DragIndex <> .ListIndex Then        ListText = .List(DragIndex)        .RemoveItem DragIndex        .AddItem ListText, .ListIndex + Abs(Shift = vbShiftMask)        .ListIndex = .NewIndex        End If        End With       End Sub       ********END PASTE********              Now click on an item and move your cursor to a new spot in the list.       When you release the mouse button, the item will be **inserted at** the       location of the mouse indicator; i.e., all existing items from the drop       point to the end of the list will placed after the item that was dragged       into the new position. This means that you can't drop an item into the       last position. To allow for that, you can press the Shift Key when you       drop the item. Doing that will place the dragged item **after** the       itemt the drop point. The Shift Key action works anywhere in the list,       but its main purpose is to allow an item to be dragged to the last       position.              There was a somewhat lengthy thread about a year ago in the vb.general n       ewsgroup on the news.devx.com public news server in which someone       offered code that inserted the dragged item **before** if that occurred       at a ListIndex lower in value than where the dragged item came from and       inserted the dragged item **after** otherwise. I found that somewhat       unnatural but others in the thread disagreed (if I recall correctly).       Here is that person's function and my response to his post:              "Reid Nix" |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca