My Google-Fu is failing me.

My Google-Fu is failing me.

I want to select the text in the selected cell of a TStringGrid.

In other words, I want the user to be able to select a cell for editing, and immediately change all the text in the cell without having to manually highlight the text in the cell or use the backspace key to delete the existing text.

Is that clear?

Comments

  1. David, thanks for the answer.

    OnGetEditText appears to allow me to set the text that gets edited, but not to highlight it.

    Or perhaps I am missing something.

    ReplyDelete
  2. I read "change all the text" to mean that you wanted to set it in code. You want the text to be highighted when you enter edit mode.

    But that is the default behaviour. So I now have no idea what you are asking.

    ReplyDelete
  3. This works for me out of the box when I activate goEditing and goAlwaysShowEditor in the grid options. It might not work when the cell is already selected. Clicking into the selected cell will just position the caret.

    ReplyDelete
  4. A couple of more details. The Grid is set to RowSelect. The problem occurs when the cell is selected in code by pressing the F2 key.

    The customer wants to be able to operate completely mouse free, so we have to provide key strokes for everything you'd normally do with a mouse.

    I need to manually reproduce the result of clicking a cell with the mouse to put the cell into edit mode.

    Thanks for your answers.

    ReplyDelete
  5. It's really a waste of time if the question is partially specified. Now, if you'd only shown code to reproduce the behaviour, then that would have been more helpful. Surely you know this by now. It's one thing a total newbie being imprecise when asking, but really, you should know far better.

    ReplyDelete
  6. David -- Thanks for the chastising.

    Now, how do you suggest that I post the code, given that the unit is about 600 lines long?

    I await your expert advice.

    ReplyDelete
  7. AFAIK, RowSelect mode doesn't play well with your requirements. I don't know of any settings or methods that would result in the behavior you describe. You might at least need a class helper to access protected methods from the grid. It is more likely that you have to declare a derived class that implements what you need.

    ReplyDelete
  8. Uwe -- I'm coming to the same conclusion about RowSelect --

    ReplyDelete
  9. RowSelect is incompatible with editing.

    ReplyDelete
  10. Bill Meyer Yeah, figured that part out -- have to change the Options values in the OnCellClick and elsewhere to maintain the ability to RowSelect and edit a cell.

    ReplyDelete
  11. Nick Hodges Please don't feed the trolls.

    ReplyDelete
  12. Nick Hodges  You provide a cut down example that demonstrates the issue, and contains just the details necessary to demonstrate the issue at hand.

    ReplyDelete
  13. I usually fake it by overlaying a TEdit on top of the selected cell.When the selected cell changes I quickly move my TEdit to yonder location.

    ReplyDelete
  14. Nick Hodges David Heffernan excels at chastising people.

    ReplyDelete
  15. Mike Margerum​ So you think that there's nothing to be gained from taking the time to ask a clear and precise question. That no matter how poor the question is that should not be pointed out?

    ReplyDelete

Post a Comment