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

Thread: listboxes

  1. #1
    Guest

    listboxes

    how do I make it so I have one listbox, with a certian number of elements, and the user can drag one element to a position in the listbox before another element. For example, in this listbox there are the elements "A" , "B" , "C",
    and "D." They are in the order A, B, C, D. How do i make it so that the user can click on d, drag it up above b, click again, so that the order now would be A, D, B, C?


  2. #2
    Join Date
    Jul 1999
    Location
    Israel
    Posts
    140

    Re: listboxes

    Here is an example for what you want:
    Private Sub List1_DragDrop(Source As Control, X As Single, Y As Single)
    On Local Error Resume Next
    If Source.List(Source.ListIndex) = "" Then Exit Sub


    Dim lCount As Long, lItemPositionY As Long
    Dim lItemHeight As Long

    lItemHeight = SendMessage(List1.hWnd, LB_GETITEMHEIGHT, 0, 0)
    Dim nNewPlace As Integer

    lCount = List1.ListCount
    nNewPlace = lCount
    For nItemIndex = 1 To lCount
    lItemPositionY = nItemIndex * lItemHeight * Screen.TwipsPerPixelY
    If Y < 0 Or Y = 0 Then
    nNewPlace = 0
    Exit For
    End If
    If Y < lItemPositionY Then
    nNewPlace = nItemIndex
    Exit For
    End If

    Next nItemIndex



    List1.AddItem Source.List(Source.ListIndex), NewPlace 'Adds the item to the target

    Source.RemoveItem Source.ListIndex 'Removes the item from the source
    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

Featured