1

I am developing a Windows Forms application that uses a DataGridView for a user to enter some data. The user enters the data into a DataGridViewTextBoxCell. This works fine, however if the user wants to go back and edit that data, the existing text there automatically gets selected and overwritten when the user starts editing.

I would like the DataGridViewTextBoxCell to behave more like a regular TextBox control. I want the user to simply be able to insert the carat anywhere in a DataGridViewTextBoxCell they have already entered text into, and then start editing without any existing text being overwritten.

Any suggestions?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Atari2600
  • 2,643
  • 2
  • 20
  • 18

1 Answers1

0

You can catch the CellClick event and then call dataGridView1->BeginEdit(false) to start editing the cell without highlighting the content. However, this is not a perfect answer as this will place the caret at the end of the content and not where the mouse was pressed.

Eldad
  • 1,067
  • 16
  • 36
  • Thanks Eldad! This should work just fine, despite the caret getting placed at the end of the cell, because the user needs to click the cell first to make it active. Now that the text is not highlighted, the user can easily insert the caret anywhere in the text. – Atari2600 Dec 23 '10 at 16:21