Datagrid selection

Hallo,

I am using Visual Studio.net 2003. When i press ctrl + A in the datagrid all rows get selected, which is the default behaviour. Which event gets  fired when i press ctrl+A In keydown event handler either "ctrl" gets captured or "A". Can anybody explain me how  the rows get selected Or which method gets called by this event

thanks
swingme


Answer this question

Datagrid selection

  • sar3000

    Unfortunately there is no easy way to achieve this.

    The datagrid control has a method called ProcessGridKey which gets to look at any key presses before you - the select all code is in here.  You can find this method using Refletor.  The good news it is protected, so you can override it and handle the ctrl+a (or any other keys) yourself.

    Hope thats useful.
    Simon.

  • rungsan

    Ok, you need to create a descendant datagrid, and override the ProcessGridKey method.  Something like this in c# (apologies for any typo's I'm writing this straight into the forum).

    public class MyNewDataGrid : DataGrid
    {
       protected override bool ProcessGridKey(KeyEventArgs ke)
       {
          if (ke.KeyCode == Keys.A && ke.Control)
          {
            //Do whatever you want to do here instead of select all...
          }
          else
             return base.ProcessGridKey(ke); //let the base class deal with other keys...
       }
    }

    That should give you an idea.

    Simon.


  • vitjan

    hallo simon,

    thanks for ur response.could u please give me a small example

    swingme

  • MELO

    Hallo Simon,

    it captures only one key. i mean either ctrl or ATongue Tied. dont know how to do it.

    thanks
    swingme


  • SaurabhKhurana

    I'm sorry, I've looked into this a bit more, and the code sample I gave you doesn't work (the method i was overriding isn't virtual! Oops).  I've looked into it a bit more, and can't seem to get work you need.

    Sorry.

  • Datagrid selection