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

Key Press Events and GridControl

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

1 Reply

AD Administrator Syncfusion Team 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
}

Loader.
Up arrow icon