By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,673 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,673 IT Pros & Developers. It's quick & easy.

DataGrid and the "Enter" Key pressed...

P: n/a
.... is being consumed. I added an event handler for the "keypress" event
and my delegate
never gets executed. Why? I am trying to catch the "enter" key pressed
event to prevent
the DataGrid from going to currentRow + 1. Instead I want it to give focus
to the next cell (currentCol + 1) to the
right if not at the end of the row.

Example:

/**
* I have a grid with 3 columns. As the user enters in data and presses
"enter" ('\r') key
* I want the cell focus to move to the right instead of down (row + 1,
currentCol).
* Can this even be done?
*/

DataGridCell current= dataGrid.CurrentCell;

if(current.ColumnNumber < 2)
dataGrid.CurrentCell= new
DataGridCell(current.RowNumber,current.ColumnNumbe r + 1)
// else by default if I do nothing it should create a new row and put me at
the first cell.

Thanks,

Byron


Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Byron,

I guess that the keypress event for the datagrid is not fired because you're
actually in a textbox control (when pressing 'enter' in a datagrid cell).
I found the next code which may help you in an inherited datagrid to swap
the enter key with the tab key (which should move focus to the next cell)

protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg,
System.Windows.Forms.Keys keyData)
{
if(msg.WParam.ToInt32() == (int) Keys.Enter)
{
SendKeys.Send("{Tab}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData)
}

Regards, Jim

"Byron McClain" <by***********@privatebusiness.com> schreef in bericht
news:%2****************@TK2MSFTNGP10.phx.gbl...
... is being consumed. I added an event handler for the "keypress" event
and my delegate
never gets executed. Why? I am trying to catch the "enter" key pressed
event to prevent
the DataGrid from going to currentRow + 1. Instead I want it to give focus to the next cell (currentCol + 1) to the
right if not at the end of the row.

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.