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

Actually, this seems to work well:

Row = Me.RowFromXY( x, y )
If Row < 0 Then Row = Me.RowFromXY( x, y - 1 ) + 1 // The row 1 pixel above + 1

or

Row = Me.RowFromXY( x, y )
If Row < 0 Then Row = Me.RowFromXY( x, y + 1 ) // before the row 1 pixel below

Hmmmm, I seem to be getting the same inconsistency with all of those examples.

I don’t mind having the users drop the dragged row onto the actual hightlighted row in the 2nd Listbox (that works consistently)…if we could disable the “in-between” drop indicator. Unfortunately, if you turn off the Drop Indicator, then the actual rows don’t get highlighted when you drag something over them.

Also, anything dropped all the way on the bottom of Listbox2 always goes to the top.

this is probably because Row = 0 or lower:
Me.AddRowat(row, obj.Text)
so, it insert the new Row at the top of the ListBox.

It is possible the “gap between rows” is more than one pixel so “y + 1” is still not landing on a row. So try the following.

Also dropping below the last row is returning -1. If y is more than 0 we must be below the last row, so we can correct for that.

Row = Me.RowFromXY( x, y )
If Row < 0 Then Row = Me.RowFromXY( x, y + 2 ) // before the row 2 pixels below
If Row < 0 and y > 0 then Row = Me.LastRowIndex + 1 // below all rows

Another way would be to draw an indicator yourself using the CellBackgroundPaint event. Just invalidate the listbox when the mouse moves (e.g. in the DragOver event) and draw the indicator based on the stored row.

Yeah, I tried around with adding 2 or 3 on the code as well, but no change. It might be just how it is. :frowning:

You code fixing a row dragged to the bottom and staying on the bottom works great though!!

I was thinking about that very thing. A few days ago, I saw someone in the forums write up a solution for that very thing. I’ll have to hunt it down again.

Actually, take a look at DropObjectOnRow event:
https://documentation.xojo.com/api/user_interface/desktop/desktoplistbox.html#desktoplistbox-dropobjectonrow

The example code is wrong but this should work:

Sub DropObjectOnRow(x As Integer, y As Integer, obj As DragItem, action As Integer, row As Integer, parentRow As Integer, location As DesktopListbox.DropLocations) Handles DropObjectOnRow
  Select Case location
  Case DesktopListBox.DropLocations.AfterAllRows
    Me.AddRow obj.Text
  Case DesktopListBox.DropLocations.AfterRow
    Me.AddRowAt( Row + 1, obj.Text )
  Case DesktopListBox.DropLocations.OnControl
    Me.AddRow obj.Text
  Case DesktopListBox.DropLocations.OnRow
    Me.AddRowAt( Row, obj.Text )
  End Select
End Sub

I’d be inclined to add/subtract half a row-height.

I like making my own indicator, as Xojo’s built-in one doesn’t look the way I want. I don’t like the “in-between” placement.

So, working on making my own indicator. I’ve got this so far.

I’ve got this in the celltextpaint event.

If DroppedRow > -1 and row = DroppedRow Then
  
  
  g.ForeColor = RGB(44,101,217)
  
  g.FillRect(0,0, Me.Width, me.Height)
  
 
  
End If

The blue isn’t quite right to match Xojo’s built in color coming from the first Listbox, but I’ll work on it.

Now I just need to figure out how to change the cell text white while it’s drawing a blue rect, and then remove the blue rect after the drop.

Changing the code to CellBackgroundPaint fixes some of the text color issues. Still can’t get the blue graphic to go away after the drop. g.ClearRectangle(0, 0, Me.Width, me.Height) doesn’t work, because it turns the row color to the window color, and not the white of the Listbox.

Try the “DropObjectOnRow” code. It should solve all the problems without you needing to paint anything. If you are on a Mac the colour isn’t alway blue. Nor would it be correct in dark mode.

Unfortunately, it doesn’t solve the problem at all…and you still have to have the built-in drop indicator on as well, which has that “in-between” state I dislike.

I’m liking what I’m seeing so far with making my custom indicator with Xojo’s turned off. I just need to nail down some of the graphic code.

What operating system are you on?

macOS 13.4

And latest XOJO IDE.

Same here and it works perfectly. I’ll send you my project to try.
http://www.ditl.org/test.xojo_binary_project

For colours. Look at:

Var colHighlight As Color = Color.HighlightColor

You’re using AP2, I’m using AP1. As I mentioned above, I’m sticking to AP1 for this project until later. Way too much to convert and figure out right now.