How to select the entire text of a textbox (edit control) for a TemplateColumn?

Apr 14, 2010 at 8:52 PM

If I have 2 columns, one a TextColumn and a TemplateColumn bound to the same property, I find that both of them behave differently when you begin editing.

For one the TemplateColumn doesn't get Keyboard focus - you need to press Tab once or Click in the cell to begin typing in the new value. Setting the FocusedElement attached property solved this one for me.

Next by default, the entire text should be selected - this works for a TextColumn, but not for a TemplateColumn. I tried setting a style with a GotFocus event setter - this works for normal textboxes but didnt work for one that is embedded within an edit template.

Tried using the various BeginEdit PrepareCellForEdit events : In these events the edit cell data template has not been expanded - the passed in UI Element is ContentPresenter with null Content. So can't get a hold of the textbox to do a textBox.SelectAll(). What is the right point to hook-in ; at which the data template has been expanded.

The code to repro this can be seen at - http://stackoverflow.com/questions/2640327