Selecting text inside a datagridview on enter

0
0

Is there a way to make text inside a DataGridViewTextBoxCell select (highlight) at the start of the cell edit? I’ve noticed if I select the text in another cell it will continue to select in subsequent cells I click in. If you put the cursor in the middle of the value, it will place the cursor in the middle of subsequent cells as you click or arrow through them. It’s like it’s remembering the previous cursor condition and trying to maintain it. I’d like to just auto-select all the text on enter, so the user can enter a new value “on top” of the existing.

  • You must to post comments
0
0

Hi Nick,

did you try setting the DataGridViews EditMode to “EditOnEnter” ?

Best regards
Frank

  • You must to post comments
0
0

Yes sir, it is set to EditOnEnter currently. I also tried firing dataGridView.BeginEdit(true) from the cell enter event. I tried using beginEdit with different edit modes on the grid. None of these attempts worked.

If it’s at all relevant, I have the input type on the cellTextBox set to numeric.

  • You must to post comments
0
0

InputType.Number doesn’t support text selection in the browser: https://html.spec.whatwg.org/multipage/input.html#do-not-apply

I tried in a small sample with standard text fields and tabbing does select the full text.

  • You must to post comments
0
0

Wow thank you! I didn’t realize that, but that’s exactly what it was.

 

Thank you for your help!

  • You must to post comments
0
0

One additional note, if someone else ever stumbles on this. The downside of changing the field input type to text was that on mobile devices it now brings up the keyboard when you click in the field, instead of the number pad. But after reading the link Luca provided, I decided to try “Tel” as the input type, and now get both the select all and the number pad when the cell goes in to edit mode.

Thanks again for the help!

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.