Listbox - First row returns -1

If you can’t create a sample that can reproduce the problem, it will be hard to fix. Can you create one without confidential invoice information?

At least do some basic description. I tried this, I expected some result, instead I got some other result. And the OS, the OS version and the Xojo version.

The idea is that you create a simple project that demonstrates the problem. You then add that to the Issue along with configuration and any other pertinent information. I don’t care what your system info is, but Xojo will. Posting it here is no help. Your issue is still content-free, and the first response of Xojo will be, where is the project?

Found in which event?

this should work

Function MouseDown(x As Integer, y As Integer) Handles MouseDown as Boolean
  System.DebugLog(CurrentMethodName) 
  
  Var row As Integer = Me.RowFromXY(x,y)
  If row = DesktopListBox.NoSelection Then
    System.DebugLog("NoSelection") 
  Else
    System.DebugLog("Row "+row.ToString()) 
    Var id As String = Me.CellTextAt(row, 0) '... use CellTagAt with a Integer
    System.DebugLog("ID "+id) 
  End If

  Return True

End Function

your issue is the order of events so the selection was not done

You can remove MouseDown and add something like

Sub SelectionChanged() Handles SelectionChanged

  Static lastID As String = ""
  
  Var num As Integer = me.SelectedRowIndex
  
  If num >= 0 then // There's a selection
    
    Var curID As String = Me.CellTextAt(num, 0) // What id?
    
    If curID <> LastID then // New ID selected, remove noise as sort column
      
      lastID = curID // Anotate to detect new changes
      
      MessageBox(curID) // Show
      
    End
    
  End
  
End Sub
1 Like

i wrote a day before

@Rick_Araujo
Your code worked great.

Thanks

1 Like