开发者

Stop text from being highlighted/overwritten in a DataGridViewTextBoxCell

开发者 https://www.devze.com 2023-01-30 22:33 出处:网络
I am developing a Windows Forms application that uses a DataGridView for a user to enter some data. The user enters the data into aDataGridViewTextBoxCell. This works fine, however if the user wants t

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 st开发者_StackOverflow社区art editing without any existing text being overwritten.

Any suggestions?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消