issue with overriding ProcessCmdKey() in DataGrid

G

Guest

Hello. I have wrapped the DataGrid control with my own class (SmartDataGrid)
adding some necessary functionality. My current webform has 2
SmartDataGrids. The first is populated by selected information from a drop
down box. The second datagrid is populated by viewing details from a row of
the first datagrid.

When editing individual rows (in either datagrid), clicking the enter key in
any editable textbox calls my inital search function that populates my first
datagrid. I want the enter key to tab to the next location. yes, simple!

All the documentation I've come across tells me to override the
ProcessCmdKey(). So I did just that. Here is my code...


public class SmartDataGrid : System.Web.UI.WebControls.DataGrid
{
override protected 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);
}
}

The error i'm getting is "no suitable method found to override". I have
found this article (HOW TO: Trap Keystrokes:
http://support.microsoft.com/kb/320584/EN-US/) in the KB and the one HUGE
difference is that their example overrides the
"System.Windows.Forms.DataGrid". I'm overriding the
"System.Web.UI.WebControls.DataGrid". If i change from one to the other then
i have 3 different overrides that give me the same error (the ProcessCmdKey
acutally compiles in this case).

I've run out of ideaRs..........
thanks for your help in advance...
 
B

Bruce Barker

in the web version of the grid, the keystrokes happen on the client unknown
to the server, so this methods don't exist. what you want done has to be
done with client script. any javascript book will give enough info to do
this.

-- bruce (sqlwork.com)
 
G

Guest

thanks bruce. duh! ok that makes sense. about the javascript: i actually
have already done that. here's the function...(instead of tabbing this one
clicks the update button of the currrent editable row).

however, my issue still exists. even after my Update_Command() function is
called my initial search function (btnSite_Click()) is called as well. I can
place break points in both and within one request both breakpoints are hit.

function ProcessCmdKey(event,id)
{
var key=event.keyCode;
if(key==13) //check for the return key...
{
alert("you've hit the enter key...");
document.getElementById(id).click();
}
}


--
jibran :^).



Bruce Barker said:
in the web version of the grid, the keystrokes happen on the client unknown
to the server, so this methods don't exist. what you want done has to be
done with client script. any javascript book will give enough info to do
this.

-- bruce (sqlwork.com)
 
B

Bruce Barker

the enter key fires a postback, unless client code captures it and cancels
the event.

-- bruce (sqlwork.com)


jibran said:
thanks bruce. duh! ok that makes sense. about the javascript: i
actually
have already done that. here's the function...(instead of tabbing this
one
clicks the update button of the currrent editable row).

however, my issue still exists. even after my Update_Command() function
is
called my initial search function (btnSite_Click()) is called as well. I
can
place break points in both and within one request both breakpoints are
hit.

function ProcessCmdKey(event,id)
{
var key=event.keyCode;
if(key==13) //check for the return key...
{
alert("you've hit the enter key...");
document.getElementById(id).click();
}
}
 
G

Guest

Hi Bruce. I'm undertanding what i need to do. I have added a startup script
to my form with this line:

Page.RegisterOnSubmitStatement("submit","return DisallowEnterKey(event);");

here is my javascript function.

function DisallowEnterKey(event)
{
alert("key kode in DisallowEnterKey(): "+event.keyCode);
if(event.keyCode==13)
return false;
}

however, everytime the function is called the keyCode is always 0. it is
never 13 when i hit the enter key. Any ideas?
thanks
jibran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top