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
close icon

Control in the grid is moved to the next cell when Enter key is pressed.

Hi,

My windows form contains DataBoundGrid and few buttons. I have assigned one of the button in the form as "AcceptButton" property of the form. When I press ENTER key while the control is focused on one of the gridcell, the control is moved to the next cell of the grid instead of performing accept button click event. How can I invoke AcceptButton click event, when an Enter key is pressed.

Thanks,
Ravi.

2 Replies

AD Administrator Syncfusion Team August 22, 2006 04:34 AM UTC

Hi Ravi,

To raise the click event of the button when the ENTER key is pressed, you need to handle the CurrentCellKeyDown event to call the PerformClick() method for AcceptButton(windows Button Control).

private void gridDataBoundGrid1_CurrentCellKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyData == Keys.Enter )
{
e.Handled = true;

//For Normal Windows Button Control
AcceptButton1.PerformClick();

//For GridPushbutton celltype.
GridPushButtonCellRenderer cr = this.gridDataBoundGrid1.CurrentCell.Renderer as GridPushButtonCellRenderer;
if( cr != null)
{
gridDataBoundGrid1_PushButtonClick( sender,null);
}
}
}

private void gridDataBoundGrid1_PushButtonClick(object sender, GridCellPushButtonClickEventArgs e)
{ MessageBox.Show("Clicked"); }

Let me know if this helps.
Best Regards,
Haneef


RA Ravi August 22, 2006 05:39 AM UTC

Thanks Haneef, It works. I have migrated my code from Syncfusion 1.6 version to 4.2 version, with the old version without using your workaround code it works.

Loader.
Live Chat Icon For mobile
Up arrow icon