Going OOP ?

In a Listbox, I have code to move in a Row from Cell(0) to Cell(Lact_Column) and back (between others).

I wanted (stupid idea) to put that code in the Listbox Subclas I’ve created tod eal with EditCopy / EditInsert / and some others.

Unfortunately, the code have errors when moved, perfect where it is.

What’s wrong with it ?

[code]Function CellKeyDown(row as Integer, column as Integer, key as String) As Boolean
If Key = Chr(9) Then
If Column < (Me.ColumnCount - 1) Then // *
// Not in the last Column ? So set it in the next Column
Me.EditCell(Row,Column+ 1)

ElseIf Column = (Me.ColumnCount - 1) Then // *
  // Set the Cursor in the first Column (0)
End If

End If
End Function[/code]

  • Listbox bug work-around.
    the - 1 part in: (Me.ColumnCount - 1)

Not looking in details, Chr(9) is tab. Maybe after processing the method the framework try to move the insertion point to another place and you need to take care of it returning True?

And for 2019r2+ you should be using ListBox.CellEditableAt zero based?

Hi Rick,

since xojo (nor Real Studio, nor REALbasic) had a Tab constant, so I usd Chr(9).

If I return True, I left the ListBox.Cell Edit mode.
If I do not use -1, I am editing a non existent Column (try the code without that mius 1 in (Me.ColumnCount - 1)…

These are not Syntax Errors (If I recall correctly the reported errors).

It’s not syntax, it’s logic.

For this part, you could return, but fire your edition call using a timer, in an immediate mode, that will be fired just after such return.

I do not return error messages, Xojo do.
What Xojo says, it there are Syntax Errors…

Argh ! These errors appears elsewhere (a work in orogress: I finished it). Once corrected, no more errors.

I feel tired right now… :frowning:

OK, I’m going to be for what I hope will be a good nap: either my brain is bugging or it is Xojo, or ?

Emile, I fought with this one a long time ago and here’s the code I wound up using (for pre-2019r2). You should create a subclass of Listbox and put this in the CellKeyDown event. Add a property named ‘mCurrentColumn’ with a default value of zero.

[code]Function CellKeyDown(row as Integer, column as Integer, key as String) Handles CellKeyDown as Boolean
#If TargetWindows
#Pragma unused column

// If the user TABs or SHIFT-TABs move to the next or previous cell

If key = chr(9) Then // the TAB key
If Keyboard.ShiftKey = False Then
mCurrentColumn = mCurrentColumn + 1
If mCurrentColumn = Me.ColumnCount Then mCurrentColumn = mCurrentColumn -1
Me.EditCell(row, mCurrentColumn)
Return True
mCurrentColumn = mCurrentColumn - 1
If mCurrentColumn < 0 Then mCurrentColumn = 0
Me.EditCell(row, mCurrentColumn)
Return True
End If
End If

Return False
End Function
Lastly, in the CellClick event put

mCurrentColumn = column

Create an instance of the subclass on your window and it will this will give you a listbox that lets you TAB across to the right, stopping at the last column, and SHIFT-TAB to the left, stopping at the first column.

Thank you Gale.

@List Mom:
Yes, Gooing OOP was an error at first, but once I saw it I loved it. Is there’s something wrong in that sentence I have to know (so I will not do it in the future) ?

You’re welcome. But the name is Dale, not Gale.

Oooops ! And I checked twice !

Sorry Date.

Hum… I wrote Daturday minutes ago. May be tired.
No. I am not correctly in front of the MacBook Pro, that is certainly why I mistype a character here and there.

Have a nice week-end.