Re: Deleting rows from DataGrid

From: Jacek Hełka (Jacek.Helka_at_potis.com.pl)
Date: 03/09/04


Date: Tue, 9 Mar 2004 13:45:15 +0100

Thank you.
This is quite complicated way, but i think, that it will work good.

Regards,
Jacek.

"""Jeffrey Tan[MSFT]""" <v-jetan@online.microsoft.com> wrote in message
news:z6nZVECBEHA.564@cpmsftngxa06.phx.gbl...
> 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: DataGrid Editing using Keyboard.
    ... 1> Derive the DataGrid and override its WndProc method to handle the ... 2> In your override, you can do hit testing to decide when you want to set ... "Camel" wrote: ... > I have a datagrid in a Winform. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • RE: DataGrid Editing using Keyboard.
    ... > 1> Derive the DataGrid and override its WndProc method to handle the ... > 2> In your override, you can do hit testing to decide when you want to set ... > the cursor, or when you want to call the base class and let it set the cursor. ... >> I have a datagrid in a Winform. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: [FORM] Catching Minimize event
    ... Override the WndProc method of the form and look for the WM_SYSCOMMAND ... > Regards. ... > Didier BRETIN ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • ComboBox in DataGrid,
    ... in this case I need to override its original behaviours. ... /// Implementation of a ComboBox as a column in a DataGrid ... private ComboBox internalComboBox = new ComboBox; ... private int rowNum = -1; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: issue with overriding ProcessCmdKey() in DataGrid
    ... in the web version of the grid, the keystrokes happen on the client unknown ... The second datagrid is populated by viewing details from a row ... > override protected bool ProcessCmdKey(ref System.Windows.Forms.Message ... > found this article (HOW TO: Trap Keystrokes: ...
    (microsoft.public.dotnet.framework.aspnet)