ListBox double-click, copy data to a new window

I’ve got a very puzzling issue and don’t know how to track it down. I’ve got 2 windows each with a listbox of data. Double clicking on a row copies the row data to a new detail window putting the data into fields. Basically the identical code in each. One works, one doesn’t. Here’s an overview.

A set of records is downloaded to a local app into a window with a listbox of 5 columns. There’s more columns in the data than can be displayed so the data is put into a record class and stored as a row tag for each row. If the user wants to view the details for a row in the listbox they double-click it. The rowtag is parsed and the data is put into fields on a new window. Here’s a sample of the code that works:

Var cRecord As RecordClassClient=me.RowTagAt(me.SelectedRowIndex)
//INDIVIDUAL DATA TAB PANEL
winClientRecord.txtClientData(0).Text=cRecord.id_clients

First line it reads the rowtag and puts the data into a record class. It does that perfectly. Next it goes through the cRecord class and puts the correct data into the correct field.

Here’s the code that does not work.

Var cRecord As RecordClassDoctor=me.RowTagAt(me.SelectedRowIndex)
//INDIVIDUAL DATA TAB PANEL
winDoctorRecord.txtIndividualData(0).Text=cRecord.first_name

This reads the rowtag correctly but then errors on the next line with an “OutOfBoundsException”. These are the first lines of the double-click method for each listbox.

I’m at a loss on this one.

I have other listboxes that function the same way. To fix those I had to reset my “For” loop counter tracking. I had updated about 2000 instances of deprecated code. Ones I’m fixing are related to the rowset and the difference between the ColumnCount and the LastRowIndex inside the returned rowset. The LastRowIndex is 0 based so my counter was off and the fields I was assigning the data too was off and sometimes both were off.

could be that this 0 element did not exists in this window
winDoctorRecord.txtIndividualData(0).

I’m afraid not. It’s a control array and is the first item. It’s the second line of code. I have other listboxes coded for the same purpose in the same way. There isn’t much to go on to debug.

do you mean a control set in a window? if yes its possible to reindex the controls. i believe

I updated the code to make this the first line:

winDoctorRecord.pListIndex=me.SelectedRowIndex

It saves the row index from the listbox to a property in the new window. That crashes. I was trying to eliminate anything to do with the control array by doing this.

I have previously saved versions from about a month ago where this work.

Not this ? So it is the other one: you try to access one too far in your for loop;

Try to append -1 at the end of your For loop line…

if nothing is selected it can be -1
var a As Integer = Listbox.NoSelection

I meant:

For Loop_Idx = 0 To Cnt - 1 // Here stands the -1 *
  • to avoid the outofboundsexception…

In other areas yes that was the issue…going deeper into the iteration than there were elements. I did the thing with a -1 or changing the counter in some way. But now that’s not an issue because I changed the first line to get the row index from the listbox and put it into a property in the new window.

It’s like one window won’t work with the other. But just in this case.

Add a break in the code and follow values in the debugger.

1 Like

In trying to simplify this I added 2 buttons. One with this code:

winDoctorRecord.Show

and one with this code:

winClientRecord.Show

The first one crashes due to the OutOfBoundsException. The second is good.

I’m starting to think maybe something is corrupted? Maybe something got messed up in the Big Sur 11.2.2 issue where my project file got converted to binary? And I had to take some untested steps to try to recover the files back to git readable files?

Use the debugger to determine where the error stands.

Maybe I’m missing something when you refer to the debugger? If you are referring to stepping through the code from a set break point I’m doing that. There’s only one line of code. There’s no values, no variables, nothing. It just open a window.

winDoctorRecord.Show

Are you perhaps talking about logging some of the environmental stats when an exception is thrown? I’m not sure how to debug one line of code other than making sure it’s correct.

Meanwhile…I went to another machine where a recent but correctly working version of the app is. I exported the window that’s the problem and imported it on the main machine into the most up to date code. That works and seems to have solved the issue.

These ar three lines and can be deomposed as many more.

In the debugger, you can get the values of each atoms from these three lines and that is what you need.

What is the value of me.SelectedRowIndex ?

What is inside winDoctorRecord.txtIndividualData(0).Text ?

What is inside cRecord.first_name ?

Are one of these Nil ?

The debugger is able to tell you that.

And, where are your error checking code ?

OutOfBoundsException:
you try to read something that does not exists; in your case, apparently, it is either a Row r a Cell who does not exists.
Are-you sure that the correct field # exists ?

Think: you have the code and have troubles; we do npt have the code… so we can only guess (bet ?).
Last idea:

expand your code into many lines from:
Var cRecord As RecordClassDoctor=me.RowTagAt(me.SelectedRowIndex)
//INDIVIDUAL DATA TAB PANEL

to:
Var cRecord as RecordClassDoctor
Var Sel_Row As Integer

Sel_Row = Me.SelectedRowIndex

cRecord = Me.RowTagAt(Sel_Row)

etc. And run. (the debugger allows you to look into each atoms of this code, but with this code, it will be easier, maybe).

Maybe I’m missing something when you refer to the debugger?
Do you have played with the debugger PopupMenu ?

Important read:
http://documentation.xojo.com/getting_started/debugging/debugger_usage.html

I do not found more precise doc.

Old IDE screen shot. Is different in the current version:

I run an old OS and then cannot fire Xojo 2020r2.1

Variables at the top-right is a PopupMenu.
CurrentRow = the Selected Row (#1)
LB_Data is the ListBox
me (cLB) is a ListBox custom Class
Self is the owner’s window.

These are built-in

Beside those, I do not have more ideas to share.

good, could be that this source code was different or xojo break the intern used data in other project.
if you use .Show its one row but it should jump into this Open (or similar name…) event.

if you have trouble with your own source code, test it row for row in a button click event and let the window events empty.

What does the debugger show if you step through the code to that point?

I moved on from the listbox double-click error. None of the code I posted earlier is in question. Just the code above. Two buttons, two one liners. Nothing to debug or step through. It’s just a 1+1=2 situation that runs amok.

What is winDoctorRecord? What is its definition?

What is the value of me.SelectedRowIndex ?

What is inside winDoctorRecord.txtIndividualData(0).Text ?

What is inside cRecord.first_name ?

All those values are correct. Yes, I do use the debugger as we both understand it. I’ve moved on from working with this code because it’s not the problem. Please see my previous post.