RE: Deleting rows from DataGrid

v-jetan_at_online.microsoft.com
Date: 03/07/04


Date: Sun, 07 Mar 2004 08:49:06 GMT

Hi Jacek,

Thank you for posting in the community!

Based on my understanding, you want to intercept into the "delete" key
press process, and do prompt for the user.

====================================
I think you can intercept the "delete" key's keydown and keyup event of
datagrid, then do your prompt.

To achieve this, you should inherit from the datagrid class, then override
the WndProc method, at last, you should intercept the WM_KEYDOWN and
WM_KEYUP message.

During I am writing the sample code, I found that it seems that WinForm
datagrid control has already intercept into the "delete" key message. So if
you just override the WndProc method, you can not intercept it.
So you should also override ProcessCmdKey method, force the datagrid to
forward the "delete" key message to the WndProc. Like this:

private int WM_KEYDOWN=0x100;
private int WM_KEYUP=0x101;
private int VK_DELETE=0x2e;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
        Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
        if((msg.Msg == WM_KEYDOWN || msg.Msg == WM_KEYUP) && keyCode ==
Keys.Delete )
        {
                return true;
        }
        return base.ProcessCmdKey(ref msg, keyData);
}

protected override void WndProc(ref Message m)
{
        if((m.Msg ==WM_KEYDOWN || m.Msg ==WM_KEYUP ) && m.WParam.ToInt32()
==VK_DELETE )
        {
                MessageBox.Show("you pressed delete!");
                return;
        }
        base.WndProc (ref m);
}

For these constant values in the code, you can figure it out through a tool
named APIviewer followed by VB6.0.

=======================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.



Relevant Pages

  • Re: Messages...
    ... What delphi does, and I like alot, is to provide a system for mapping ... a chain of windows procedures to your object and it's ancestral line. ... want to intercept an existing message, then you have the possibility of ... override the various click methods exposed by TControl. ...
    (comp.lang.pascal.delphi.misc)
  • Re: 508 compliant (i.e. accessible to the people with disabilities)?
    ... intercept the page's output html content and do our custom ... protected override void Render ... Control level, make our custom control wrapper (derived from the ... existing web control classes) and override the render method so as to ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: An simple class derived from CDialog
    ... Should I override the WndProc in my CDialogBaseRedBackground and ... intercept WM_PAINT message? ...
    (microsoft.public.vc.mfc)
  • Re: An simple class derived from CDialog
    ... intercept WM_PAINT message? ... I there any way to do that using the MESSAGE MAP? ... or I would override PreCreateWindow() to set the background ... brush to be a red color. ...
    (microsoft.public.vc.mfc)
  • Re: Intercepting Ctrl+C in a datagrid
    ... Howabout to override WndProc() of datagrid? ... protected override void WndProc ... > How can I intercept Ctrl+C to stop this? ...
    (microsoft.public.dotnet.framework.windowsforms)