Best Way to maintain a sequence value in a Listbox

I know there has to be a fairly simple way to do this.

  • I load a listbox from a database table, storing a “ORDER” field in rowtag
  • The user has the ability to drag the rows into a desired order
  • How can I easily determine which rowtags need to be altered…

Not just the rowtag, but the minimum amount of SQL to update the table itself

DragReorderRows

  MsgBox str(newPosition) + EndOfLine + str(me.ListIndex)

What do you want to do to the table?
Write an order by column back to it?

so that
Apple 1
Banana 2
Cherry 3

can become

Apple 2
Banana 3
Cherry 1

You need to hold the ID and original order somewhere.
how about
rowtag = theuniqueID
celltag(row,0) = the orderby value

After re-ordering,
loop through the listbox.
Any where the listindex doesn’t agree with the celltag:

update table set orderby = celltag where id = rowtag

…if I havent misunderstood…

I was hoping for something… more along

update table set seq=newposition+1 where seq=oldpostion
update table set seq=seq+1 where seq>newposition

I THINK this will work … but only if moving an item UP in the sequence

but I’m thinking you idea is “safer”… since not only can the user drag the order, but they can drop new records as well, and those new records have to derive they sequence position from the current “listindex” (ie. insert after)

Ok… sigh.

How to distingush between… “DRAG” and “Multiple Select”

I need to select one or more records in Listbox 1 to drag to Listbox 2

But if I click a row, and move the mouse… it starts selecting rows, NOT dragging the single row…
and if I select multiple rows, and try to drag. it unselects all but the last row