Listbox cellkeydown issue

I have a listbox. I click on a cell and make it editable via the cellclick event :

Me.CellType(row, column) = Listbox.TypeEditable

I edit the contents of the cell, press Enter, and catch that in cellkeydown.

if key = chr(13) then me.cell(row,column) = "Changed!" end if

Result: No change. Whatever I typed in is now in the listbox.

I’m sure it’s just something I’m not understanding. I encountered this in a large program I’m writing. To test I created a simple program with nothing more than a window and a listbox. Same problem occurs in both.

Windows 10.

how can it be “NO CHANGE” -AND- what you typed in in the listbox?
Isn’t that what you wanted?

Also did you return TRUE or FALSE in the KEYDOWN?

[quote=328826:@Dave S]how can it be “NO CHANGE” -AND- what you typed in in the listbox?
Isn’t that what you wanted?

Also did you return TRUE or FALSE in the KEYDOWN?[/quote]

I wanted the cellkeydown event to change the contents of the cell to “changed” after pressing Return. It does not. Instead it takes whatever I have typed since editing the cell. To be exact: I have the listbox initial values as “1” for cell 1, “2” for cell 2, etc. When I click on the cell, it sets it to editable but it takes another click to actually begin editing. I type in a word, any word. I press Return (Enter). The event catches it and reaches my line – me.cell(row,column) = “Changed!” – but that change doesn’t occur. The “1” or “2” that was there is gone and the word I typed is inserted. But the word “Changed!” … nowhere to be found.

Oh … I didn’t return as true or false. So I tried it both ways. True stops my typing from entering anything at all. False operates the same as not designating return boolean.

Changing the value of a listbox cell while editing is confusing at first. You must change the value like this.

  listbox.activecell.text = "Changed"

Think of it as a separate textfield (which I believe it is) when you change the listbox.cell that change is overwritten when the value from the textfield is written to the listbox.

The keydown of the listbox is NOT in play here… it is as Neil suggested, the keydown event of ACTIVECELL

He’s actually using CellKeyDown…

But anyway, pressing ENTER is not the only way that someone could leave the cell. I suggest putting your code in the CellAction event which should fire when the edit is complete.

Thanks, Neil, Greg, and Dave. Neil’s answer solved my problem.