Auto Advancing EditCell

I am trying to create a ListBox where the user will enter a row of single digit entries. When a single number larger than 1 is entered, I want the editable cell to advance 1 column. The code I have in the CellKeyDown event is:

[code]If key <> “1” Then
column = column + 1
End If

Me.EditCell(row, column)[/code]
The problem is nothing appears in the cell where the digit was entered. I have been fighting this all morning and am hoping for a kick in the right direction. If I don’t advance the edit cell, then the digit, of course, appears just fine. Any hints?

Return False?

Thanks for the reply, Marcus. I’ve tried returning both True and False with no joy. Returning True, in my understanding, would stop the data from being entered in the cell which is exactly the problem.

CellKeyDown will only accept the keys 2 to 9 and will beep otherwise:

Function CellKeyDown(row as Integer, column as Integer, key as String) Handles CellKeyDown as Boolean if Instr( "23456789", key ) > 0 then return False else beep return True end if End Function

If a key has been accepted by CellKeyDown then you can use the CellTextChange event to handle it:

[code]Sub CellTextChange(row as Integer, column as Integer) Handles CellTextChange
dim LastColumn as integer = me.ColumnCount - 1
dim LastRow as integer = me.ListCount - 1

select case column

case LastColumn // move to next row
if row = LastRow then me.AddRow
me.EditCell( row + 1, 0 )

else
me.EditCell( row, column + 1 )

end select
End Sub[/code]

Note that if the last column in the last row has been reached the code will add another row. If you do not want this then modify the code accordingly …

Using the CellTextChanged event instead of the cellKeyDown event to advance the editCell was the key to success.
Thanks, Marcus, for the push in the right direction.

Push? That wasn’t a push - I drove you in a Rolls Royce to your destination … :wink:

All I needed was the suggestion to use the CellTextChanged event. The rest of the code I had. No intent to offend with my thanks.

I wasn’t offended. If I was I’d let you know :wink:

P.S. you should have read my Push & Rolls Royce comment with a Monty Python voice … think Brian’s mother!