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
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?
Thanks for the reply, Marcus. Ive 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
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 )
me.EditCell( row, column + 1 )
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
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 wasnt offended. If I was Id let you know
P.S. you should have read my Push & Rolls Royce comment with a Monty Python voice
think Brians mother!