Listbox doubleclick row problem

I have used basically the same code for years to retrieve records based on the row the user doubleclicks.

The PopulateListBox and the DoubleClick events are shown below.

This problem has just started and I can’t figure it out. I have duplicated the problem on the same row regardless of how the records are sorted. The problem occurs when the 21st or following rows are clicked.

when it works ok, i contains the row number. Where the error occurs, i = -1

The PopulateListBox method:

[code]
dim i As Integer
dim j As Integer // J is just to make counting the ROW easy
dim sCaptureDate As String

	rsImages.MoveFirst
	
	lbImages.deleteAllRows
	
	j = 1
	i = 0
	while not rsImages.eof
			sCaptureDate = rsImages.Field( "CaptureTime" ).StringValue
			sCaptureDate = Left(sCaptureDate, 10)
			lbImages.addRow "1"
			lbImages.cell( i, 0 ) = rsImages.Field("pkRecID").StringValue
			lbImages.cell( i, 1 ) = rsImages.Field( "BaseName" ).StringValue
			lbImages.cell( i, 2 ) = rsImages.Field( "Title" ).StringValue
			lbImages.cell( i, 3 ) = rsImages.Field( "Path" ).StringValue
			lbImages.cell( i, 4 ) = sCaptureDate
			lbImages.cell( i, 5 ) = str(j)
			i = i + 1
			j = j + 1
			rsImages.MoveNext
	wend
	
	iCurrentRowCount = rsImages.RecordCount
	tfRowCount.Text  = str(iCurrentRowCount)
	rsImages.MoveFirst
	
	Return[/code]

The DoubleClick event of the ListBox:

		dim iRow       As Integer
		dim sImageID   As String
		dim sSQL       As String
		
		iRow       = Me.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
		sImageID   = me.cell( iRow, 0 )
		
		sSQL = "SELECT * FROM ImageMaster WHERE pkRecID = " + sImageID    // this is the problem
		rsRecall = dbSQL.SQLSelect(sSQL)
		if dbSQL.Error then
				MsgBox(dbSQL.ErrorMessage)
				Quit
		end if
		
		tpPanels.Value = 1
		PopulateDataEntryFields
		cPreview.Backdrop = nil 
		
		return

The problem occurs when “rsRecall = dbSQLSQLSelect(sSQL)” executes and it is a sql error that says Syntax error near “11” which is the pkRecID field
When the problem happens, sSQL was apparently corrupted as it has a lot of extra digits. See below

The contents of sSQL when the error does not occur:
SELECT * FROM ImageMaster WHERE pkRecID = 24

The contents of sSQL when the error DOES occur:

SELECT * FROM ImageMaster WHERE pkRecID = 1
11
2
12
3
13
4
14
5
15
6
16
20
10
22
23
24
7
17
8
18
9
19
21

Seems like RowFromXY is returning -1
Set the selected row as a property in the Change event perhaps?

here’s further strangeness:

If I put the debug flag on the iRow = … line. The error happens on EVERY row.
If the debug flag is on the dbSQL.SQLselect row, or there is not flag at all, it happens at 21 or after

I added the following code just to see and the locations fields look normal on the surface - even when the error occurs.

[code] dim iSystemMouseX As Integer
dim iSystemMouseY As Integer
dim iMeLeft As Integer
dim iSelfLeft As Integer
dim iMeTop As Integer
dim iSelfTop As Integer
dim iFinalMouseX As Integer
dim iFinalMouseY As Integer

	iSystemMouseX  = System.MouseX
	iSystemMouseY  = System.MouseY
	iMeLeft        = Me.Left
	iSelfLeft      = Self.Left
	iMeTop         = me.Top
	iSelfTop       = Self.Top
	iFinalMouseX   = iSystemMouseX - iMeLeft - iSelfLeft
	iFinalMouseY   = iSystemMouseY - iMeTop  - iSelfTop 
	
	
	iRow       = Me.RowFromXY(System.MouseX - Me.Left - Self.Left, System.MouseY - Me.Top - Self.Top)
	sImageID   = me.cell( iRow, 0 )
	[/code]

Tim

YEP!

Sorry, I don’t understand.

I’m sorry, I’m getting functions confused with each other. You don’t need to use Listbox.Change, you can just use the ListIndex to get the selected row instead of RowFromXY.

If you’re using RowFromXY to get around multiple-row selection, then you might have to get more clever with your workaround, or figure out why you’re getting a bad result from RowFromXY.

Edit: CellClick will tell you what row was clicked if you need to get into a clever workaround.

Additionally, wouldn’t me.MouseX and me.MouseY give you more reliable coordinates on the Listbox?

I just copied the code from the Listbox docs.

I have to say, I think ListBox may be the weakest component of Xojo. Why can’t they just add the functionality to it to return the row and column clicked?

changed it to use ListIndex and the problem went away in this case. But sometimes I need to know the cell that was clicked - here I just need the row

Thanks Tim

CellClick gives you this information.
http://documentation.xojo.com/index.php/ListBox.CellClick

This. Do not do this.
Read the documentation, comprehend what it does, and write your own code.

Warning: there uis two example code for this function. I took the second one (by pure error) and was unable to get the results I was awaiting :frowning: until I change it to the first one.