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

Tabbing and OnEnter

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

5 Replies

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


MB Manoj Bhaskarakurup 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


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


MB Manoj Bhaskarakurup 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


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

Loader.
Live Chat Icon For mobile
Up arrow icon