Search code examples
.netdatagridviewtextboxcell

Stop text from being highlighted/overwritten in a DataGridViewTextBoxCell


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?


Solution

  • 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.