Results 1 to 7 of 7

Thread: ListView Report mode drag and drop-please

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    I have this listview in report mode, but I want the user to be able to change the order of things, preferably by dragging and dropping, inside that one box. If you have any idea, I'd be glad to hear. note: it's not a listbox, and there aren't two boxes, just one listview that needs it's order changed around a bit.

    bob

  2. #2
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136

    Talking

    Right-click the listview and choose 'properties', and make sure the AllowColumnReorder is checked. Doesn't that do what you want? Sorry if I'm being thick, but from what you've said, it seems to be what you're after.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305
    Not the columns, but the rows. If the user has:

    1 a b c
    2 d e f
    3 g h i

    I want them to be able to drag and drop the ROWS:

    1 a b c
    3 g h i
    2 d e f


  4. #4
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136

    Talking

    Oh right. I had a piece of code to do exactly that. As I recall, it only worked for moving single rows - not blocks. Suppose you could always modify it.

    Let me have a dig around and see if I can find it.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    That's exactly what I need

    That is exactly what i want to do. It would be wonderful if you could find that.

    thanks,

    bob

  6. #6
    Addicted Member
    Join Date
    Apr 2000
    Location
    Sheffield, England.
    Posts
    136

    Unhappy

    Hi Bob,

    I dunno where you are, but I'm in the UK and it's 8:20am, just arrived at work. I searched for that bit of code last night at home, and it's nowhere to be found. The best I can offer at the moment is a simplified explanation of how it worked.

    Basically when you click on a listitem, the number of the item you clicked is stored in one parameter. When you move the mouse and release it, the number of the item under the mousepointer is stored in another parameter, giving you a start point and end point for the listitems you need to modify. For example, if you pick row 3 and want to move it to row 5, then item 3 is saved to a temporary buffer, rows 4 and 5 are moved up one row, and the item which was at row 3, is pasted to row 5. All of that is simple enough in concept.

    I've just had a go at writing the code to do this, and the only problem I haven't been able to figure out (in the 10 minutes or so that I spent on it), is how to work out which row is under the mouse pointer when the mouse button is released.

    You'll also need to access the Properties page for the ListView, and set the following:-

    OLEDragMode = 1 - ccOLEDragAutomatic
    OLEDropMode = 1 - ccOLEDropManual

    Hope that's of some use to you. In the meantime, I'll have another look for that piece of code, and post here again if I have any luck.


  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    Good news

    I got it to work-mostly. Here's what I did:

    Code:
    Private Sub ListView1_DragDrop(Source As Control, x As Single, y As Single)
    strItem1 = ListView1.SelectedItem.Text
    strItem2 = ListView1.SelectedItem.SubItems(1)
    Set ListView1.DropHighlight = ListView1.HitTest(x, y)
    ListView1.DropHighlight = ListView1.ListItems.Count
    Set Itemx = ListView1.ListItems.Add(ListView1.DropHighlight.Index)
    Itemx.Text = strItem1
    Itemx.SubItems(1) = strItem2
    ListView1.ListItems.Remove (ListView1.SelectedItem.Index)
    Set ListView1.DropHighlight = Nothing
        End Sub
    
    Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If Button = vbLeftButton Then
    ListView1.Drag vbBeginDrag
    End If
    End Sub
    It works for dragging and dropping, but there are two problems that I'm not sure how to solve now. The first is that when I drag it off or too far down or up, it gives me an error(because the index is all messed up I think). The second is that it drops it above the one I drop it on. Normally programs drop it below the selected one, and that's what I want to do, but it doesn't work when I add + 1 to the DropHighlight.Index part of the Add statement. Could you help me with this maybe?

    thanks,

    bob

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