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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Key Press Events and GridControl

Thread ID:





6273 Aug 7,2003 02:22 AM UTC Aug 7,2003 06:31 AM UTC WinForms 1
Tags: GridControl
Administrator [Syncfusion]
Asked On August 7, 2003 02:22 AM UTC

I have a GridControl and I only want to allow numerical data to be entered into each cell. I want to ignore any keypress that doesn't have the value '0' to '9', '.', '-' and Insert and Delete. I have found hooking onto the event: CurrentCellValidateString Will work in stopping a keypress when first trying to start editing the cell, but if the cell has already begun editing, you can enter any key after that. What event should I be hooking onto for this type of operation? cheers Alan

Administrator [Syncfusion]
Replied On August 7, 2003 06:31 AM UTC

Try handling CurrentCellKeyPress, and set e.Handled = true for any e.KeyChar that you do not want the cell to get.
private void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;

	//restrict col 2 to numbers
	if(cc.ColIndex == 2 && !char.IsDigit(e.KeyChar) 
            && e.KeyChar != ’.’ && && e.KeyChar != ’-’)
		e.Handled = true; //ignore it


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon