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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

User Control Keypress in Cell

Thread ID:

Created:

Updated:

Platform:

Replies:

5871 Jul 22,2003 10:37 AM UTC Jul 23,2003 04:56 AM UTC WinForms 3
loading
Tags: GridControl
Martin
Asked On July 22, 2003 10:37 AM UTC

Hi I'm using a custom control in a cell by setting the CellType to "Control" and setting the CellStyle.Control property. The custom control is derived from a standard TextBox, but when the grid goes into Edit Mode for this cell, it stops all the cursor key presses from getting to the control. Is there any way round this so my control can handle the cursor keypresses (also Tab, Delete etc)? Thanks Martin

Administrator [Syncfusion]
Replied On July 22, 2003 12:31 PM UTC

You can catch the CurrentCellKeyDown event and explicitly handle the keys if your control is the current cell. The snippet below has a TextBox named box as a "Control" cell type, and these snippets moves the right and left arrow keys in the control.
private void gridControl1_CurrentCellKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(cc.ColIndex == 2 && cc.RowIndex == 2)
	{
		Keys keyCode = e.KeyCode;

		if(keyCode == Keys.Tab || keyCode == Keys.Delete

			|| keyCode == Keys.Left || keyCode == Keys.Right)

		{

			string s = "";
			switch(keyCode)

			{
				case Keys.Delete:
				break;

				case Keys.Tab:
				break;
				case Keys.Left:
					if(this.box.SelectionStart > 0)
						this.box.SelectionStart--;
					break;
				case Keys.Right:
					if(this.box.SelectionStart < this.box.Text.Length)
						this.box.SelectionStart++;
					break;
			}
			e.Handled = true;
		}
	}
}

Martin
Replied On July 23, 2003 03:38 AM UTC

But doing this would mean duplicating code that my control already should handle, as well as just the arrow keys, also escape doesn't go through (which I use as an undo edit feature) also copy & paste, selection of text by holding down shift, etc etc... Thanks.. Martin

Administrator [Syncfusion]
Replied On July 23, 2003 04:56 AM UTC

Then in your derived control class, expose a method (make it public) that allows you to effectively call your controls' OnKeyDown (which is protected). Then in the above handler just call this newly exposed method to let your control process any given key.

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.

Warning Icon 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.Close Icon

;