# Auto Advancing EditCell

**URL:** <https://forum.xojo.com/t/auto-advancing-editcell/43305>\
**Category:** General\
**Created:** [May 3, 2018, 3:22pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305 "2018-05-03T15:22:42Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [May 3, 2018, 3:22pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/1 "2018-05-03T15:22:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [May 3, 2018, 3:26pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/2 "2018-05-03T15:26:55Z")

</div>

Return False?

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [May 3, 2018, 3:37pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/3 "2018-05-03T15:37:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [May 3, 2018, 3:45pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/4 "2018-05-03T15:45:42Z")

</div>

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 

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [May 3, 2018, 6:40pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/6 "2018-05-03T18:40:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [May 3, 2018, 7:02pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/7 "2018-05-03T19:02:03Z")

</div>

> [@386047:@Roger Clary](#):
>
> 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  😉

---

<div class="post-metadata">

**Author:** ![Roger\_Clary](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@Roger\_Clary](https://forum.xojo.com/u/Roger_Clary)\
**Post date:** [May 3, 2018, 8:02pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/8 "2018-05-03T20:02:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [May 3, 2018, 8:04pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/9 "2018-05-03T20:04:39Z")

</div>

I wasnt offended. If I was Id let you know 😉

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:12pm UTC](https://forum.xojo.com/t/auto-advancing-editcell/43305/10 "2020-10-29T19:12:09Z")

</div>


