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.
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.
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.
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
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.
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.