Setting a listbox cell editable

I have a listbox in which I set a cell to editable when it is added to the list. That works fine as long as the user enters a title. However, I would like to catch the case where the user just hits Return and the new listbox item is just boilerplate title text (lstCandidates.AddRow(“[Enter candidate title here]”).

So I’d like to make the cell editable again when this happens, to get the user to put something more relevant in the celltext.

I tried this in the CellAction event:

if me.CellTextAt(me.LastAddedRowIndex,0) = "[Enter candidate title here]" then
// User didn't add a title
  lstCandidates.EditCellAt(me.lastAddedRowIndex, 0)
end if

but this is just ignored. I tried setting the focus back to the list and then using EditCellAt but that throws StackOverflowExceptions. I suspect that I’m missing the obvious… any direction appreciated.

Create a new method in your window and move the line

lstCandidates.EditCellAt(me.lastAddedRowIndex, 0)

to that method then update your CellActionEvent handler to:

if me.CellTextAt(me.LastAddedRowIndex,0) = "[Enter candidate title here]" then
// User didn't add a title
  Timer.CallLater(0, AddressOf [Newmethodname])
end if

This will allow the CellActionEvent Handler to complete before re-entering the EditCellAt method.

1 Like

Thanks for the response. Interesting; I haven’t come across CallLater before, so I will do a little exploration.

It’s a slippery slope hack that will make tracking down bugs a living nightmare. With event timing issues like this it can be shorter than adding a timer and all that, but you should leave it in the darkest corner of your mind and pull it out rarely.

I’ve spent some time on this and I can’t get it to work. I’m going to sleep on it and see whether another solution/approach comes to me.

Thanks for the input anyway, Wayne and Tim.