Dropping a row where indicator is, and shifting rest of rows downward

I’ve put together a small example app with two listboxes that can move rows from one side to the other. I can reorder the rows in their respective listbox without triggering the DropObject, edit cells, etc. All is good with one exception. I have the Drop Indicator turned on for the 2nd Listbox, but when I drag a row over to it from the 1st Listbox, it doesn’t drop the row in that location. It drops the row at the bottom of the other rows. I guessing there is some extra code I’ll have to write to make this work, but can’t figure it out. I’ve spent the weekend looking at desktop listbox documentation (I have this example app in AP1 and AP2), and searching for examples and videos, but for the life of me I couldn’t find this information out.

I’d appreciate any help here, and I feel I’ve come to a brick wall. This is for only dropping one row, as multiple row dragging is not needed for my app. And for now, let’s stick to a API1 solution. I won’t be converting my larger project to API2 at this time.

Thanks!

Perhaps use the dragover event to tell you where you are over the DesktopListbox? Use rowfromxy to tell you the row number, then add a row at that point.

Are you calling AddRow when dropped. Look at AddRowAt( RowNumber ). As Tim says use RowFromXY to get the correct row number.

Only thing I’m accomplishing with RowFromXY is having each row show up at the top of the 2nd Listbox instead of the bottom. Also, I don’t think DragOver is the right event, as that triggers as soon as the mouse enters the Listbox, not where it is ultimately dropped. Perhaps MouseUp or DropObjectonRow makes more sense? Either way, the logic isn’t working.

Here’s what I have in DragOver for Listbox2:

Var xValue As Integer
xValue = System.MouseX - Me.Left - Self.Left
Var yValue As Integer
yValue = System.MouseY - Me.Top - Self.Top


row = Me.RowFromXY(xValue, yValue)

And here’s what I have in DropObject for Listbox2:

If obj.TextAvailable Then
  Me.AddRowat(row, obj.Text)
End If

Instead of all that calculation. There is the Listbox2.MouseMove( x as Integer, y as Integer ) event.

X and Y are relative to the control:

row = Me.RowFromXY( x, y )

Does that work?

I’m also assuming that “Row” is a property of the second listbox. Otherwise, you need to get the value from the first event to the second.

Row is a window integer property I created.

It will work there but you would have to use Self.Row in the listbox.MouseMove event. I would suggest moving it to the Listbox (make a subclass), that way you have different versions for different list boxes.

So, putting the in the MouseMove event makes no difference.

I am using

row = me.RowFromXY( x, y )

self doesn’t work, and give a "Window1.ListBox2.MouseMove, line 1
Type “Window1.Window1” has no member named “RowFromXY”
row = self.RowFromXY( x, y )
"
error.

I’m only dragging one direction, so shouldn’t a window property be ok?

This should be the MouseMove and DropObject events. Obviously the “Text” part should be your dropped object’s text.

Sub MouseMove(x As Integer, y As Integer) Handles MouseMove
  Row = Me.RowFromXY( x, y )
End Sub

Sub DropObject(obj As DragItem, action As DragItem.Types) Handles DropObject
  Me.AddRowAt( Row, "Text" )
End Sub

Self refers to the Window, not the Control. If you want to refer to the control you can use Me.

If you are only dragging to one list then yes, a Window property will work. It could be worth calling it something like DroppedRow, just to make it more explicit.

Getting the whole “End Sub error”. Looked it up, and found your comments from another thread a few months ago explaining it to another gentleman. I still don’t get it.

I can’t paste it right into the IDE. Nothing happens when I paste it into the MouseMove event, and as I said if I put the literal text into the code, I get the End Sub error. It also errors if I remove the sub and end sub around the code you provided.

I’ve never had any luck with sub code examples. Sometimes…SOMETIMES…functions will resolve themselves into methods (which I understand and use regularly), but I’ve had no luck with subs.

With the cursor flashing here (ringed):

pasting the while function will result in something like this:

You are not allowed Sub or End Sub in that box.

If you have the green here, like this:

Then you can paste the whole function in and it will generate the event as required.

Oh, I tired that! I promise I’m not that dense! The problem is, I have no paste option on the Listbox. Only have a paste option on the Windows and events.

You can paste at any point. Just select paste from the Edit menu, rather than a contextual menu. Which may be an issue? If that doesn’t work then create the events manually and copy and paste the contents (but not he Sub or End Sub) into them.

I’ve never thought you were dense :slight_smile: Its a very odd issue and hard to explain. It is something you could show very simply face to face but writing it out is hard.

Paste is greyed out from edit menu. Closed project, didn’t save, re-opened fresh version. Same thing.

I tried removing the sub and end sub before, but like I was saying i get a syntax error.

Window1.ListBox2.MouseMove, line 1
Syntax error
MouseMove(x As Integer, y As Integer) Handles MouseMove

It seems you can’t paste the whole event in. Perhaps it only works with methods, which is odd. It does work with methods.

Here is how it should look:

When I say you must remove the Sub and End Sub, You need to remove the whole line not just those words. The whole Sub line is the event definition.

That was my bad!

OK, got it compiled but exact same thing.

I looked at what the row number is when the row itself is being dropped and the first one is always zero, and the others are always -1, no matter where they are dropped.

To clarify, the row can be -1, 0, or 1. Nothing else.

OK, remove the MouseMove event completely. Add a new DragOver event and put this in it.

Row = Me.RowFromXY( x, y )

So this is weird. Now it works when I drag directly on the row and it’s highlighted. If I drag in-between the row (using Xojo’s drop indicator turned on) it sometimes works…and sometimes it doesn’t work, instead appearing above the two rows I’m trying to place it in-between. There’s no rhyme or reason to it.

Yes, I noticed that. I suspect that RowFromXY is failing to return a valid value for the gap in between, which seems like a bug. You could try the following just after Row = line. Assuming Row is negative when it doesn’t work.

Row = Me.RowFromXY( x, y )
if Row < 0 then Row = Me.RowFromXY( x, y - 1 )

Its a workaround but would likely do the job.

It looks like Me.RowFromXY is returning -1 when you are “inbetween” rows. Not very useful.