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.
Syncfusion Feedback

Tabbing and OnEnter

Thread ID:

Created:

Updated:

Platform:

Replies:

57891 Mar 13,2007 05:48 PM UTC Mar 16,2007 02:11 PM UTC Windows Forms 5
loading
Tags: GridControl
Manoj Bhaskarakurup
Asked On March 13, 2007 05:48 PM UTC

Hi,

I am using a GridDataBoundGrid control. I have 5 columns in my grid. After I enter some value in the first and second column, upon tabbing from the second column I want to create a new row in the grid and place the cursor in the first column of the new row that is created. Right now on tabbing the cursor moves to the next column on the same row.

Also on pressing Enter key in the current row, I want to create a new row and the cursor should be in the first column of the new row that is created.

Thanks
Manoj

Administrator [Syncfusion]
Replied On March 13, 2007 06:59 PM UTC

Hi Manoj,

You can handle the CurrentCellKeyDown event of the grid add the Rows to the underlying datasource. And alos you can navigate the currentcell using the MoveTo method. Here is a code snippet

private void gridDataBoundGrid1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Tab || e.KeyData == Keys.Enter )
{
e.Handled = true;
GridDataBoundGrid grid = sender as GridDataBoundGrid;
DataTable dt = grid.DataSource as DataTable;
if( dt != null)
{
DataRow dr = dt.NewRow();
dr[0] = dt.Rows.Count;
dt.Rows.Add(dr);
dt.AcceptChanges();
int FirstColIndex = grid.Binder.FieldToColIndex(0);
int RowIndex = grid.Binder.PositionToRowIndex(dt.Rows.Count - 1);
grid.CurrentCell.MoveTo(RowIndex,FirstColIndex);
}
}
}

Best regards,
Haneef

Manoj Bhaskarakurup
Replied On March 14, 2007 10:04 PM UTC

Hi,
I try to use this code snippet but was not able to get the output as expected.
As I said earlier, I would like to do the following, create a new row upon tabbing or onenter from the second column of the current row and the cursor should be in the new row's first column.
The code that you sent is not working as per the above requirement.

Thanks
Manoj

>Hi Manoj,

You can handle the CurrentCellKeyDown event of the grid add the Rows to the underlying datasource. And alos you can navigate the currentcell using the MoveTo method. Here is a code snippet

private void gridDataBoundGrid1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if( e.KeyData == Keys.Tab || e.KeyData == Keys.Enter )
{
e.Handled = true;
GridDataBoundGrid grid = sender as GridDataBoundGrid;
DataTable dt = grid.DataSource as DataTable;
if( dt != null)
{
DataRow dr = dt.NewRow();
dr[0] = dt.Rows.Count;
dt.Rows.Add(dr);
dt.AcceptChanges();
int FirstColIndex = grid.Binder.FieldToColIndex(0);
int RowIndex = grid.Binder.PositionToRowIndex(dt.Rows.Count - 1);
grid.CurrentCell.MoveTo(RowIndex,FirstColIndex);
}
}
}

Best regards,
Haneef

Administrator [Syncfusion]
Replied On March 14, 2007 10:37 PM UTC

Hi Manoj,

Please try the attached sample and let me know if this helps.
GDBGEnterTabKey2ndColumn.zip

Best regards,
Haneef

Manoj Bhaskarakurup
Replied On March 15, 2007 05:08 PM UTC

Hi,

I saw the attached project and it works fine, but in my case there is one more problem. I am using a collection object as the datasource for my grid, and when I use AddNew() it creates a new row in the grid but some of the columns are disabled in the new row.

Thanks
Manoj

>Hi Manoj,

Please try the attached sample and let me know if this helps.
GDBGEnterTabKey2ndColumn.zip

Best regards,
Haneef

Administrator [Syncfusion]
Replied On March 16, 2007 02:11 PM UTC

Hi Manoj,

Is it possible for you to upload us a sample or modify the browser sample to reproduce the issue here? This will help us to analyse the issue further.

Best regards,
Haneef

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

;