Listbox many rows mouse selection

I have a single column Listbox, which is populated with data from a text file. This all works ok and there are about 150 rows, of which I can see 15 at a time. A vertical scrollbar appears automatically.

I use a CellClick event attached to the Listbox.

Until recently I could use the mouse to scroll up and down the list, and then select an item not initially visible. This would then be processed - no problems.

Recently, this has changed - I can still scroll up and down the list with the mouse, but if I select an item that is not visible initially, when I click it, the list scrolls back up to the top, and shows the item in the equivalent position to the one I clicked as being selected. So if e.g. I scroll down and then click the item that is 4 rows from the top of what I can now see, I get the item that is 4 rows from the top of the list.

If I use the keyboard down arrow to move down the rows, each row is selected in turn and if I then press Return when the required item is selected, this item is selected correctly, and the list does not scroll back up to the top.

MacOS Mojave and Apple Magic Mouse (no actual scroll wheel, but the surface acts like one).

I recently updated to Xojo 2021.1 - I don’t think the change mentioned happened at the same time as the upgrade, but it may have done. There has been no change to the MacOS or hardware.

Has anyone any idea why this behaviour should have changed, and what to do about it?

Thanks

Create a demo project and share it, please.

I see no change for ListBox in 2021r.1 Release Notes.

Thanks Emile. This is very strange - I’ve been trying to create a simple project to show the error, but have failed.

I have an earlier version of the project which still works ok, and I’ve compared this and the faulty one using Arbed, and there are only 4 differences, none of them material to this problem. So it is a complete mystery. I don’t like to say that something in coding is inexplicable, as I believe there is always an explanation; but this problem is as near to inexplicable as I can imagine, and I don’t have the time, expertise, or even the will to investigate further!

So I’m now going back to the earlier version, and will develop further, with frequent and careful testing of course!

Many thanks in deed for your trouble

Sounds like you are reloading the entire list in response to a click?

What events are defined for the listbox?

Desktop or Web?

Desktop

No. The Listbox is loaded only in the LB Open event. Other events for the LB are CellClick and DoubleClick, which do different things

Are you able to upload a video of it happening?

1 Like

I’ve made a video, but can’t upload it. The upload button only allows jpeg etc. So I’ve put it on Dropbox, with this link

The video shows what happens twice,

1st time. I click on Item 9 Sunday which I can see without scrolling, and then scroll down to below the bottom & click on the last item (item 20 Friday), this is NOT selected as it should be. Instead, it jumps back to the first visible “screen” & selects item 15 Thursday which is the same (i.e. last) row on the 1st “screen”

2nd time. I scroll down without first selecting an item I can see without scrolling, and exactly the same happens - it goes back to the first screen and selects the same visible row, as I clicked (the last one that is visible).

Please see my reply to Emile above which shows my workaround

Thanks for your interest - it would be good to find this error, but I’m not hopeful of doing so!

I should have mentioned that if I use the keyboard (up & down arrows and Return key) to select, everything works fine!

I have something similar, but with two ListBoxes (same window or different window)…

Very strange.

That is a very strange one, I assume you’re not doing anything overly complex that you haven’t mentioned (you’d be surprised what people forget to mention when asking for help). I can only really recommend adding a private feedback ticket and including the project that shows the issue.

Thanks Julian

I’ve cut the project down to it’s minimum & found how to avoid the error, which is certainly good. The original project is quite complex, so there were about 20 controls to remove!

None of the changes I’ve made have explained the strange mouse-click behaviour shown in the video, but I’m not inclined to take this any further now, having not exactly solved the issue, but at least found how to avoid it.

Many thanks to you and the others who responded

I’ve cut the project down to it’s minimum & found how to avoid the error,

When this was happening to me, my own code was refilling the list/changing the selection
Im sure you have found something similar in the change , click, or lostfocus events.
We would benefit from hearing what it was, rather than leaving the post hinting it might have been a bug in the list… :slight_smile:

1 Like

I do understand your point! I’ll try to pinpoint the problem and post again in the next day or so

I think I have solved this - I don’t suppose you want to see the actual code, but in case you do, here is the code that loads the Listbox:

Listbox1.RemoveAllRows 'comment out this line and scrolling / selection error disappears

Var textInput As TextInputStream
Var i As Integer = 0
Var f as FolderItem = Specialfolder.Desktop.child(“Xojo Projects”).child(“HPC”).child(“HPCtests”).child(“data.txt”)
If f <> Nil And f.Exists Then
textInput = TextInputStream.Open(f)
textInput.Encoding = Encodings.MacRoman
While Not textInput.EndOfFile
ListBox1.AddRow()
ListBox1.Cell(ListBox1.LastIndex,0) = str(i)
ListBox1.Cell(ListBox1.LastIndex,1) = textInput.ReadLine
i = i + 1
Wend
textInput.Close
End If
textInput.Close
End If

This is in a Method that is called from the Listbox1.Open event and also from Listbox1.CellClick event. I’m not sure why I did it this way, but there was additional code in the Method which only applied when called from CellClick. So I think the lesson I’ve learned is to keep Methods short, doing only one thing.

As it stands, the above code generates the error as in the video, but as noted in line 1, removing the first line stops this happening.

I must confess that I still don’t understand why I shouldn’t remove all rows from the listbox before loading or reloading it, but evidently I can’t! I put line 1 in because at one stage I was getting repeated data in the Listbox while the app was running.

Again many thanks for your interest and support - I hope we can now put this to bed!

You can, but not in the middle of a CellClick check.

:wink:

No worries, glad you got to the bottom of it, thanks for coming back to us with the additional info as its good to see that its not an unknown underlying issue.

You can’t do this since the event is not “after” every internal code, it could be “before”. So what you can do is create a method on your window for example say “UpdateMyListbox()” without parameters.

Timer.Callater(0, AddressOf UpdateMyListbox) 

Now the UpdateMyListbox method will be called the first event loop after your code, so basicly the same as ASAP.

When this was happening to me, my own code was refilling the list/changing the selection
Im sure you have found something similar in the change , click, or lostfocus events.

Mystery solved. You were doing exactly this. :slight_smile: