开发者

WinForms DataGridView - 3 Clicks Needed to Edit Existing Text in Cell [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Dupli开发者_StackOverflow中文版cate:

Direct access to DataGridView combobox in one click?

I'm sure this behavior is by design but I don't feel it's intuitive in many cases.

If you move your cursor to a new row by simply clicking in one of the cells of a different row than you are currently in, the first click simply moves you to that row and highlights the entire cell that you've clicked. The second click selects all text as though you'd like to delete it or overwrite it. Your third click will finally position the cursor in the location within the text where you've clicked.

Is there any way to change the behavior so that the user can move to a different row and be editing existing text inline after the first, or at least the second click?

Edit1:

So the answer given below works well. The issue at the Microsoft Discussion site where you cannot select a row if you have EditOnEnter mode enabled appears to be resolved with Visual Studio 2008.

The only question I have left is, as the user moves to the next record using tab or if they click in the next cell, the entire text is immediately selected which could lead to unintentional overwrites. Is there a simple fix for this?

Edit2:

The solution you've give for edit1 does work, with one gotcha. The cursor will always be at the end of the text after the first click into a different cell. I don't see that this is really such a bad problem so I'm not going to worry about trying to fix it.


Change the EditMode property of your DataGridView control to "EditOnEnter".

Direct access to DataGridView combobox in one click?

http://social.msdn.microsoft.com/forums/en-US/winformsdatacontrols/thread/cab3c9eb-4c86-475e-8cbd-dee6b235765a/

[For your EDIT section answer example]

http://www.pcreview.co.uk/forums/datagridviewtextboxeditingcontrol-dont-want-text-initially-sele-t2526222.html

this.myDataGrid.CellEnter += new
DataGridViewCellEventHandler(myDataGrid_CellEnter);

void myDataGrid_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if ((this.myDataGrid.Columns[e.ColumnIndex] is
DataGridViewTextBoxColumn) ||
(this.myDataGrid.Columns[e.ColumnIndex] is
DataGridViewComboBoxColumn))
{
this.myDataGrid.BeginEdit(false);
}
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜