Need help with click error on a list box

Thanks for all the help guys especially Alex and Dale

Dale
I am running the latest version of XOJO but it is happening with earlier versions of XOJO too.
When I click on an item it is a line in the listbox not a heading or a blank line.
Note: It happens on listboxes that have no cells too. As far as I can tell it has never happened when I click on a blank line.
When I have tried it on other machines it has been a clean install of XOJO but I transferred the my program over.
The problem occurs when I click on an item a listbox and the program instantly drops back to the IDE or if I’m running a build the program just quits. Other times I get a rotating circle before it crashes.

That’s why I I’m beginning to think Alex maybe right about Norton but can’t prove it yet. There’s something in the back of my mind that tells me that Norton and XOJO don’t get along. (Hopefully I’ll remember what the problem was.)

In the mean time I’m running out of time before I have to do something else

Dave

A listbox might have change, cell click , mousedown and other events

Exactly WHICH events have you implemented?
Do you have ‘SetFocus’ anywhere in your code?

You might be suffering a stack overflow if events are cascading.
But can you please post your code and tell us which events you have implemented?
Trying to guess what your code looks like is crazy.

Are you able to replicate this in a new simple project? If you are, post an example and we’ll take a look.

If not, sprinkle your listbox events with system.debuglog’s with increasing numeric values, e.g system.debuglog(“here1”) here2 here3 etc.

Download https://docs.microsoft.com/en-us/sysinternals/downloads/debugview and run it along side your app. This will show the messages you just sprinkled around your app and will not have the flushing issues of the IDE where messages can be lost and not actually be reported to the IDE debug pane on a crash.

You’ll then be able to narrow down where your app got to before the crash and work back from there. Block comment out code until it stops happening to narrow it down even further.

Here is the code that I use to load the List box

'MsgBox “at LoadSameGroupingListBox”

//This routine will list all book locations)
Dim intAA As Integer
Dim intRecordID As Integer
Dim intTotalRecords As integer

dim strAA As string
dim strBB As string
dim strCC As string
Dim strDD As String
Dim strRecordType As string
Dim strBookName as String
Dim strAuthor as String
Dim strDescription as String
Dim strTypeBook as String
Dim strMyRating as String
Dim strLocation as String
Dim strDateLastRead as String
Dim strSameGrouping as String
Dim strCurrentSameGroupingCode As String
Dim strStartName As String
Dim strEndName As String

strStartName = “”
strStartName = Trim(txtGetSortGroupCode.Text)
strStartName = F__Aphosphes_Replace(strStartName)
strStartName = Uppercase(strStartName)
strEndName = strStartName + “||||||”
'MsgBox "start name is: " + strStartName

lstSameGroupingListBox.DeleteAllRows
lstSameGroupingListBox.TextSize = 16
intTotalRecords = 0
strCurrentSameGroupingCode = “”
//============================================================
//============================================================
//Get all christian romance books
'rs = db.SQLSelect(“SELECT * From MyBooks WHERE (RecordType) = ‘BOOKS’ and (TypeBook) = ‘CHRISTIAN ROMANCE’ ORDER BY RecordType, DateLastRead, BookName asc”)
RS_01 = DB__01.SQLSelect(“SELECT * From Table_One WHERE (Record_Type) = ‘BOOKS’ ORDER BY Record_Type, Field_08 asc”)

//note you can only SQL the access table not a querry on the tables
While Not RS_01.EOF
intRecordID = RS_01.IdxField(1).IntegerValue
int__Record_ID = intRecordID
db_Read_A_DB_Record_By_ID_Number
strRecordType =str__RecordType
strBookName = str__Field_03
strLocation =str__Field_04
strDescription = str__Field_05
strDateLastRead= str__Field_06
strTypeBook =str__Field_07
strSameGrouping =str__Field_08
strMyRating =str__Field_09
strAuthor = str__Field_10

if str__Field_08 >= strStartName then
'MsgBox "we want to show this author name in alphabetical order
'bool__SearchingTheWhloeSubject = False

//-------------------------------------------------------
//check to see if we have already processed this location code
if strCurrentSameGroupingCode = strSameGrouping then
  //we have already proessed this code do nothing
Else
  //we need to show this group code
  
  strCurrentSameGroupingCode = strSameGrouping
  strAA = Trim(str__Field_08)
  lstSameGroupingListBox.AddRow strAA
  
  intTotalRecords = intTotalRecords +1
  
end if

end if

RS_01.MoveNext
wend
RS_01.Close
lstSameGroupingListBox.addrow “”
lstSameGroupingListBox.AddRow
lstSameGroupingListBox.AddRow "TOTAL = " + str(intTotalRecords)
lstSameGroupingListBox.SetFocus

When the program gets to this point I click on one of the selection.

Do you want to see my change code also?
Dave

@David Howe — I have already run into a similar situation. To my recollection, Xojo can call a ListBox event with an invalid row or column (-1) when you click after the last row or after the last column (in case your column is shorter in width than the ListBox).

Please insert a line

if row<0 or column<0 then return

at the beginning of your event to see if it changes anything.

I can’t put your command in in my code as it says row and column
lstSameGroupingListBox.Row and lstSameGroupingListBox.column
are unknown.

Good idea though

This is how I take care the out of bounds problem.

strAA = lstSameGroupingListBox.List(lstSameGroupingListBox.ListIndex)
if lstSameGroupingListBox.ListIndex < 0 then
MsgBox “we clicked on a blank line”
exit
end if
Thanks for the idea.
Dave

PS: This listbox has no cells.

Care to explain ?

This is not an error: a Click in a non Row area * deselect the eventual selected Row(s) / allow you to do some different stuff (depends on what you do with the Listbox.

  • blank line is unknow here, as my Listbox(s) always have alternately colored Rows / Recalls me Blank Areas (™) that can appears (a bug) sometimes. :wink:

@David Howe — I can’t figure out your execution flow though. If you want to track down where the problem is after clicking on a row, you need to do it from the first Event raised by the ListBox. So what is important here is the code you have within the CellClick or Change event. So where is your code located exactly?

[quote]This is how I take care the out of bounds problem.
strAA = lstSameGroupingListBox.List(lstSameGroupingListBox.ListIndex)…[/quote]

Well, you are investigating a weird situation which is potentially a bug in Xojo. That means that you cannot assume that ListIndex has a correct value. So, before “strAA = …” I would check that lstSameGroupingListBox.ListIndex is not below zero before using it. In other words, it would be better to rewrite your code as:

if lstSameGroupingListBox.ListIndex < 0 then MsgBox "we clicked on a blank line" return //Exit is usually not a good solution. else //<<< Here, you have already checked the ListIndex value, so it is safe to use. strAA = lstSameGroupingListBox.List(lstSameGroupingListBox.ListIndex) end if

A ListBox with “no cells” means that it has no headers and no row whatsoever. In such a case, you would likely end up with -1 as the row and/or the column in an event.

[quote=444384:@David Howe]This is how I take care the out of bounds problem.

strAA = lstSameGroupingListBox.List(lstSameGroupingListBox.ListIndex) if lstSameGroupingListBox.ListIndex < 0 then MsgBox "we clicked on a blank line" exit end if [/quote]

By the time you want to check whether your ListIndex is less than zero, you’ve already crashed because you’ve already used it in the strAA = ... statement.

More generally, I don’t see how anyone here can help much until you:

  1. List which event handlers you have implemented for this listbox

  2. Show the code for each of them.

You might have missed https://forum.xojo.com/54725-need-help-with-click-error-on-a-list-box/p2#p444380 because you posted at the same time as me.

Sorry I’m having a bad day.
if you look at my reply (second one back) you will see how I load my listbox which has no cells.
The first reply back is how I read an item (the change function)
I’ll try not to cause anyone anymore trouble.

Julian thanks for the reply I’ll check it out in a few minutes

Each row has one cell

.Addrow"" does that

We dont need to see how you fill it, we need to know what EVENTS you have coded, and what they contain.

CellTextPaint
CellBackgroundPaint
Change
… what do you do??

[quote=444180:@David Howe]I’m using the IDE and have 12 Gigs of memory.
I’ve used the TRY command as the first line in the CHANGE function of the Listbox and on the mouse down & up and it never gets there. (see my original question)

[/quote]

I deduce from this that you are at least using the change event and the mouseup and mousedown events. Any particular reason for doing this? If things are to be driven by someone clicking on a row in the listbox I’d be more inclined to start off with the cellclick event. Your cellclick event will be given the row and column of the clicked cell, so you can do your bounds checking there as Stephane suggested before:

if row<0 or column<0 then return

We want to see the actual code in each of your event handlers for the listbox.

Upthread you posted:

Now, where is that code? In the open event handler for the window, or perhaps the open event handler for the listbox itself? Also, I don’t see where you open the database and initialise the DB__01 variable.

Sorry I had to take some time off and look at all the information everyone had given me

And I want to give a very big THANK YOU to Dale Arends. Your #6 (start from scratch with a 1 window project) got to me.
So I did a one window program with just one listbox. I didn’t have a failure.
so it started me thinking and I started turning off and on other windows but anything below the first window would fail.
In looking at the documentation I kept running across the word “COMBO” which seem to be preferred option.

So I used a combobox instead of a listbox and to my amazement I haven’t I haven’t click failure yet. Of course I’ve only been trying for a couple of hours. LOL

But I really want to thank Dale again because he gave me a starting point I could work with, and while I didn’t solve the problem; I believe I have found a work around that I can live with.

Thanks to everyone who tried to help me (I know I’m NOT the easiest person to work with)
sometimes I just need to get away and start with the basics to solve a problem
Dave