Listbox - First row returns -1

I have a listbox filled with invoice info from a database. It has a header. When I click on the first row it returns a -1. which of course is out of bounds. Should the first row return a 0 or am I misunderstanding the documentation.


The first row is 0, so something else is going on.

I know that the first row is 0. Hence the post.

Empty rows return -1

I answered the question you asked.

Without your code, we can’t tell what might be happening


The label is Row Pressed but it’s just move over the cell

The top one is HEADER, so -1

Another related subject. I think I’ve found a bug. Allow Row Reordering is OFF, but clicking on the HEADER the listbox reorders

Another one. Painted the BACKGROUND of grey, but the cell contents erased it?

1 Like

You didn’t want to use FillRectangle by any chance? Your code does exactly what it is supposed to do.

Because lack of coffee? I typed draw… then got the options, got this one, and puff! For a moment I thought we got another regression. Thanks for this one.

1 Like

My guess is that is an unfortunate API 2 renaming of EnableDragReorder and has nothing to do with sorting…


1 Like

From the docs:

AllowRowReordering As Boolean

If True, you can reorder rows within the DesktopListBox by dragging rows.

So if “Allow Row Reordering” is not the property to disable the row reordering (that we can fire clicking at the column headers for example), what’s the correct one?

Incomplete design here?

Clicking on the header causes it to be Sorted, which is not what AllowRowReordering is about. AllowRowReordering allows the user to drag and drop rows into any order they wish. You can prevent sorting using the following. Obviously you can do it for some or all columns.

Me.ColumnSortTypeAt( Me.AllColumns ) = DesktopListbox.SortTypes.NotSortable

As usual, people need to read the documentation. Throw code together by all means - I do it all the time - but when it doesn’t work the docs (and testing) should be the first port of call.

1 Like

Thanks. Not an obvious simple way of enable/disable the feature. It may demand some bit more clarification on the docs, and adding a cross reference at the AllowRowReordering and ColumnSortTypeAt.

I do, and looking at the obvious places (property to enable/disable) I couldn’t find. The feature was hidden somewhere.

There’s a difference between sorting (clicking on a header) and reordering (via D and D).

And… how do you remove the small icon (the “sorted” icon in the sorted column) ?

In the standard API:
LB.SortedColumn = -1
LB.HasHeading = False
LB.HasHeading = True

Works fine with xojo 2021r2.1…


It’s the small icon in column “Untitled 3”…

Sure, sorting is the reordering of a complete set using a rule, and just reordering can be partial, like switching places of just 2 rows. So, disabling reordering, it is expected disabling sorting too.

But one is set in the Properties Pane, the other is a simple click in the Header ???

It should follow the sorting column disable feature.

I do not know, but once I click in a Column Header, I get the small icon. I use that code to clear it (in a MenuHandler).