Listbox Dragging problem :(

Hi,
I have a listbox which allows drag reordering.

When I drag a row up - it all works fine, BUT, if I want to drag a row down 1 place - I need to actually drag it down 2 places, otherwise nothing happens.
Basically - when dragging a row down, I have to drag it an extra row down, in order for it to be placed where I actually want it to be.

Any ideas?

Thank you all in advance.

I’m not seeing that running Yosemite, latest version of Xojo and compiling for Cocoa. I drag down one row and that is where it goes

Oh no - that is what I feared :frowning:
I will need to check for conflicting code then.

Thanks.

Richard,

Is it an error related to 0-based vs 1-based Properties ?

Richard,

I am not 100% sure how your code is written, but you must ensure the following pertaining to your Listbox’s DragReorderRows event.

  1. You must determine the direction of then drop compared to the originally selected index in order to correctly reposition your entry. For example:

// ---------------------------------------- DETERMINE IF THE NEWLY DROPPED ENTRY IS ABOVE OR BELOW THE ORIGINAL SELECTED INDEX
Dim dropDirection as Integer

Select Case newPosition

Case is > Me.ListIndex
// DROP DIRECTION IS ABOVE THE SELECTED INDEX
dropDirection = 0

Case is < Me.ListIndex
// DROP DIRECTION IS BELOW THE SELECTED INDEX
dropDirection = 1
End Select

  1. For Index Drops BELOW the Originally Selected Index you must add a +1 to your newPosition to correctly reposition it. For example:
    // ---------------------------------------- RE-INSERT INTO REORDERED POSITION
    Dim theNewPosition as Integer = newPosition+1
    me.InsertRow (theNewPosition,"")
    me.cell(theNewPosition,1) = me.cell(me.ListIndex,1)
    me.cell(theNewPosition,2) = me.cell(me.ListIndex,2)
    me.cell(theNewPosition,3) = me.cell(me.ListIndex,3)

  2. You must Remap your DB ID’s from the Old Position to the New Position via your RowTags:
    // ---------------------------------------- REMAP ID FROM OLD POSITION TO THE NEW POSITION ROWTAG
    me.RowTag(theNewPosition) = me.RowTag(me.ListIndex)

  3. You now must Remove the Old Selected Position Entry:
    // ---------------------------------------- REMOVE THE SELECTED OLD POSITION
    me.RemoveRow(me.ListIndex)

  4. You Must Reposition your entries properly so they are correct in your Database. I usually put this following code into a method:
    // ---------------------------------------- THIS METHOD JUST REMAPS THE ROWTAGS PROPERLY
    for i as integer = 0 to Listbox2.ListCount-1
    Listbox2.Celltag(i,0) = i+1
    next i

  5. NOTE:::: For Index Drops ABOVE the Originally Selected Index you must USE THE newPosition UnModified to correctly reposition it. For example:
    // ---------------------------------------- RE-INSERT INTO REORDERED POSITION
    Dim theNewPosition as Integer = newPosition // <-- Not Modified
    me.InsertRow (theNewPosition,"")
    me.cell(theNewPosition,1) = me.cell(me.ListIndex,1)
    me.cell(theNewPosition,2) = me.cell(me.ListIndex,2)
    me.cell(theNewPosition,3) = me.cell(me.ListIndex,3)

  6. REPEAT STEPS 3-5 Since they are the same

So when you write your final code block you can see that you need to select case on the dropDirection to know which route you will take (Either Above or Below the Selected Index.)

HTH!

Woweeee - that was exactly it :slight_smile: