We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Text editing like a regular edit control

Thread ID:

Created:

Updated:

Platform:

Replies:

7908 Oct 14,2003 10:44 AM Oct 15,2003 11:42 AM Windows Forms 4
loading
Tags: GridControl
Laurie Spencer
Asked On October 14, 2003 10:44 AM

Hello, I have one editable cell in my grid derived from GridTextBoxCellModel. I would like the editing behavior to be exactly like that found in Windows Explorer when you rename a file or directory. I overrode OnKeyDown to handle the arrow keys, but just preventing focus from leaving the cell on arrow keys is insufficient. There are so many special cases that I found myself basically implementing the cursor behavior of an edit control. I'm wondering if there is an easier way (some property I can set?)to get that functionality. Thanks! Laurie

Administrator [Syncfusion]
Replied On October 14, 2003 12:31 PM

I am not sure what you what to do. If I right-click a filename in Windows Explorer, I get the name highlighted with a cursor on the right-end of the name. Is this what you want - the text to be highlighted when the cell goes into editmode? If so, you can use the grid.ActivateCurrentCellBehavior property to handle this, setting it to SelectAll. (The cursor is at the left side, but that can be moved in CurrentCellControlGotFocus). But I suspect I am missing the point of what you need...

Laurie Spencer
Replied On October 14, 2003 12:52 PM

Thanks for the reply! Yes I got the select all part. Here's where I am with this (from OnKeyDown): if ((e.KeyCode == Keys.Up) || (e.KeyCode == Keys.Down )) { e.Handled = true; } else if (e.KeyCode == Keys.Right) { if (TextBox.SelectionLength == TextBox.TextLength) { TextBox.SelectionStart = TextBox.TextLength; TextBox.SelectionLength = 0; e.Handled = true; } else if (TextBox.SelectionStart + TextBox.SelectionLength == TextBox.TextLength) { e.Handled = true; } } else if (e.KeyCode == Keys.Left) { if (TextBox.SelectionLength == TextBox.TextLength) { TextBox.SelectionStart = 0; TextBox.SelectionLength = 0; e.Handled = true; } else if (TextBox.SelectionStart == 0) { e.Handled = true; } } } else { base.OnKeyDown(e); } This is incomplete: the control key still causes the edit control to lose focus. If the first n characters are selected then the left arrow key doesn't work. Plus more little special cases like that. I was hoping that there is an easier way to get the ctrl key, shift key, mouse selection, arrow key functionality without recreating an edit control. Thanks! Laurie

Administrator [Syncfusion]
Replied On October 14, 2003 05:28 PM

If your main concern is not leaving the cell when your user hits any of the arrow keys, you might be able to do it a little simpler using the CurrentCellMoving and just cancel the move if an arrow key was hit. (You could also use your selection code at this point to move the edit control cursor if you need to.)
Keys lastKeyCode = 0;
private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
	lastKeyCode = e.KeyCode;
}

private void gridControl1_CurrentCellMoving(object sender, GridCurrentCellMovingEventArgs e)
{
	if(lastKeyCode == Keys.Left || lastKeyCode == Keys.Right || lastKeyCode == Keys.Up || lastKeyCode == Keys.Down)
	{
		e.Cancel = true;
	}
}

Laurie Spencer
Replied On October 15, 2003 11:42 AM

Thanks - much simpler! Laurie

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;