CellAction and SelectRowIndex

I have a ListBox with several columns and rows.
I edit a cell and then according to the Language Reference:

If a cell is editable, a CellAction event occurs when the user finishes editing a cell. Row and Column are zero-based.

Notes

“Finishing editing” is defined as exiting the cell after clicking in it. Tabbing out of the editable cell or clicking another cell triggers this event. Clicking a checkbox in a checkbox cell also qualifies as “finishing editing”.

My problem is:

  1. If I click another cell the edited row is not selected.
  2. If I press return or tab, then the edited row is selected

Is there a way to prevent this selection of the row?
I’ve tried putting this:
Me.SelectedRowIndex = Listbox.NoSelection
in a lot of places but I couldn’t prevent the selection of the row.
Any help?

You can handle the return, enter and tab keys. In the CellKeyDown event, if the key is one of them, get out of the edit mode (using me.SetFocus) and then “return true” to prevent the key from going further.

Thanks Arnaud. I will try and inform you.

You’re welcome. Waiting on your result.

Hi, Arnaud

The truth is that something strange happens.
I added, according to your suggestion, the CellKeyDown event with this code

If key = Chr(3) Or key = Chr(13) Or key = Chr(9) Then
  Me.SetFocus
End If

If I press Return or Enter key or if I click another cell then no row is selected (Thanks, that’s what I wanted).
But if I press Tab then the row is selected as before.
I tried to add “Return True”

If key = Chr(3) Or key = Chr(13) Or key = Chr(9) Then
  Me.SetFocus
  Return True
End If

But it’s worse, because now even the Return or Enter keys select the row. Only clicking another cell doesn’t select the row.
Have you any idea about what’s happening?

Hi Ramon,

I’m sorry to come back so late for your issue (as you probably know, my Xojo doesn’t work these days).

While it doesn’t change your issue, I’d have written the other way around:

dim a As Integer=asc(Key)

if a=3 or a=13 or a=9 then

As this involves only one function, once.

Oh, I’m seeing one thing. Since you’re already editing a cell, leaving it still keeps the row selected.
A “me.ListIndex=-1” before the “return true” you added should do it.

Keep me informed how this goes (and I’ll answer faster; won’t be busy the next few days).

Isn’t Enter = Chr(4) ?

Suddenly, I have a doubt…

No, it’s indeed 3.
Windows (and Linux, IIRC) don’t differentiate between Return and Enter (at least in Xojo), where both are always 3.
Return, on Mac, is 13 so we can differentiate both and make enhanced use of the keyboard :slightly_smiling_face:
Chr(4) is the one with the arrow pointing bottom-right (at the left of Page Down) to scroll all the way down.

Yes, you are right. That way it works! Thanks a lot.
In fact I had put the line Me.ListRowIndex = -1 in many places but not here because I hadn’t used this event.
Now it works, which is what I wanted!

1 Like

Great; you’re welcome.

You are right. Age comes n the party… sad.

What may also be relevant is the frequency at which you do/did things.
Using the ascii values of keys was something I did very frequently 10 or 20 years ago. I bet I remember (some of) them better than someone who may have used them once or twice, regardless of the age, which you should force yourself to disregard :wink:.
That being said, I don’t know how much you played with them.