Home Forums WinForms controls Xceed Grid for WinForms GridControl KeyDown event not raised on Tab

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13580 |

    I have a gridcontrol with a bunch of readonly cells and when the user tabs I want it to raise the grid’s keydown event so I can select what gets focus. Instead the event is not raised and the grid loses focus to another control. How can I properly capture the tabbing on a readonly cell?

    Imported from legacy forums. Posted by jberman (had 1470 views)

    User (Old forums)
    Member
    Post count: 23064

    Just in case somone points me toward it, I already checked out the sample that exceed has on their website and it does not work properly. The tab only raises the keydown event when the cell is being edited…

    Imported from legacy forums. Posted by jberman (had 716 views)

    User (Old forums)
    Member
    Post count: 23064

    In the KeyDown event handler of the GridControl, set e.Handled to true.<code>grid.KeyDown += new KeyEventHandler(grid_KeyDown);
    void grid_KeyDown(object sender, KeyEventArgs e) {
    Keys k = e.KeyCode;
    if (k == Keys.Tab) {
    // do your stuff
    e.Handled = true;
    }
    }</code>

    Imported from legacy forums. Posted by Tommy (had 289 views)

    User (Old forums)
    Member
    Post count: 23064

    I have tried that, in fact the sample that xceed has listed under their faq uses that exactly. The problem is it raises the keydown event only when you are in edit mode, otherwise the grid loses focus to another control. Try it with a readonly cell currently selected. The event will not be raised. Unless there is a difference in how those events are raised in VB .Net as that is what I am using…

    Imported from legacy forums. Posted by jberman (had 351 views)

    User (Old forums)
    Member
    Post count: 23064

    You’re right. I tried it and got the same result. If you want to detect the leaving of the grid, you can catch the Leave-event of the GridControl.
    I think the grid was designed like this:
    – to navigate the grid, use: Left, Right, Up, Down, PageUp, PageDown, Home, End
    – press Tab to go to the next <b>input field</b>: when editing, this is the next cell in the grid, else this is the next control

    Imported from legacy forums. Posted by Tommy (had 363 views)

    User (Old forums)
    Member
    Post count: 23064

    I know they had to do this to place the grid in the normal order of tabbing between controls on the form without having to go through every cell but I needed a way around that. Too bad the leave event doesn’t tell me how the user left the grid. Thanks for all your help Tommy!

    Imported from legacy forums. Posted by jberman (had 456 views)

    User (Old forums)
    Member
    Post count: 23064

    If you really need this functionality (detect Tab-key), you can subclass the GridControl, and override the <b>IsInputKey</b> method, like this:<code>public class MyGridControl : GridControl
    {
    protected override bool IsInputKey(Keys k) {
    if (k == Keys.Tab || k == (Keys.Shift | Keys.Tab)) return true;
    else return base.IsInputKey(k);
    }
    }</code>If you use this class instead of GridControl, the <b>KeyDown</b> event will be fired when pressing Tab or Shift+Tab. Beware that the grid will also not give focus to the next control: focus will stay inside the grid.

    Imported from legacy forums. Posted by Tommy (had 433 views)

    User (Old forums)
    Member
    Post count: 23064

    Question is does my boss need that functionality =P I’ll run the idea by him. You da man Tommeh.

    Imported from legacy forums. Posted by jberman (had 423 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m not sure why this works, but it does:

    Add the following CurrentCellChanged event to the gridcontrol:

    private static void grid_CurrentCellChanged(object sender, EventArgs e)
    {
    GridControl grid = (GridControl)sender;
    grid.CurrentCell.EnterEdit();
    grid.CurrentCell.LeaveEdit(false);
    }

    Now, even though no cell is being edited, whatever state the grid is left in allows it to catch Tab keydown events.

    Imported from legacy forums. Posted by csperler (had 6399 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.