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

That is the Mac highlight color, which is far lighter blue than what Xojo uses.

In which case add a “DropObjectOnRow” event and use the following code:

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

It it doesn’t work then there must be a bug, that will likely never get fixed being API1.

That’s odd.

You may be able to access some more colours using:

NamedColor (name As String) As Color

Sorry I didn’t notice the API1 requirement earlier.

No worries. I’ll mess around with some things for now. Thank you for all your help so far!

g.ForeColor = RGB(4,74,217)

Seems to be a good match for Xojo’s Highlight color in a listbox.

So here’s where I am. I have this code in CellBackgroundPaint:

If row = DroppedRow Then
  
  g.ForeColor = RGB(4,74,217)
  
  g.FillRect(0,0, Me.Width, me.Height)
  
End If

My issues: At launch, there is a row already highlighted on the left. Obviously, I’d like this to not be there at launch.

Next, when I drop a row, it stays highlighted. I’d like to figure out how to remove the highlight after the drop.

ClearRectangle changes the row color to the window color instead of the Listbox color, which is white. And even if it worked, not sure how to trigger that after the drop, because I can’t call graphics from something like the MouseUp event.

Other than that, the dropping and row re-arrangment is working how I like it.

As long as the user’s highlight colour is actually blue.
See here:

You mean “on the right”, correct? Your screenshot doesn’t show a selection in your left listbox.

What about setting me.Listindex=-1 in the DropObject?

Then add argue you could fill a white rectangle :wink:

Maybe I’ve not followed all this thread, but you could do this in the drop event, at the very end:
DroppedRow=-1
me.invalidateCell(-1,-1) 'Or was it “RefreshCell(-1,-1)” in API1? I don’t remember.

The listbox would refresh, and since DroppedRow=-1, your code is responsible to not draw the blue highlight.

Making the rectangle white would make the text white after the clear. The text seems to hold the color.

This code you provided works for the most part, however the initial blue row is still there on the right side.

DroppedRow=-1
me.invalidateCell(-1,-1)

Putting

DroppedRow=-1

in the open event or setting the property’s initial value to -1 takes care of the initial blue colored row appearing!

I was literally about to say set it to -1 to start and after drop :slight_smile: If you don’t it starts at 0, which is a valid row.

If the text is white, it means one of these:
• the row is actually selected
• you draw the text white in the CellTextPaint event

As you’d be aware of the latter, I assume the row is selected (and you don’t want that). Then set me.Listindex=-1 to clear the selection.

I would like to thank Ian and Arnaud for their help with getting this exactly the way I wanted. I’ve leaned a lot on this little example alone!

1 Like

You’re welcome. Glad you learned things :wink:

Happy to help