Tab will not change focus to another control

Posted by: imgodot on 15 September 2017, 7:43 pm EST

  • Posted 15 September 2017, 7:43 pm EST

    Pressing tab when the last cell in the Spread is selected should set the focus to a control other than the spread, but the last cell retains the focus.

    I'm sure this is something obvious.
    So, why will the focus not move out of the Spread?

    Thanks.
    -- Paul
  • Replied 18 September 2017, 10:29 am EST

    Hi Paul,

    You can use the code as follows to move focus to next control on hitting Tab key you have the focus on last cell in a Spread Sheet.

    private void fpSpread1_KeyUp(object sender, KeyEventArgs e)
    {
    if(e.KeyData==Keys.Tab)
    {
    if(fpSpread1.ActiveSheet.ActiveRowIndex==fpSpread1.ActiveSheet.RowCount-1 && fpSpread1.ActiveSheet.ActiveColumnIndex == fpSpread1.ActiveSheet.ColumnCount - 1)
    {
    Control p;
    p = ((FarPoint.Win.Spread.FpSpread)sender).Parent;
    p.SelectNextControl(ActiveControl, true, true, true, true);
    }

    }
    }

    Thanks,
    Deepak Sharma
  • Replied 20 September 2017, 5:55 pm EST

    I have deleted all my erroneous posts.
    We did get selecting the next control working BUT your code still has a bug.

    In the KeyUp event, the grid's ActiveColumnIndex is set to the new column being entered. Therefore, with your code, when you tab into the last cell in the row, SelectNextControl is called.
    Further, once focus is in the last cell in the row, ActiveColumnIndex doesn't change.

    I see no way to make the KeyUp event work.
    However, calling SelectNextControl from within the Advance() event DOES work.

    -- Paul
  • Replied 21 September 2017, 10:55 am EST

    Hi Paul,

    Thank for bringing that out.

    Here is the correct code which you can use:

    private void fpSpread1_Advance(object sender, FarPoint.Win.Spread.AdvanceEventArgs e)
    {
    e.Cancel = false;
    if(e.AdvanceNext == true)
    {
    Control p;
    p = ((FarPoint.Win.Spread.FpSpread)sender).Parent;
    p.SelectNextControl(ActiveControl, true, true, true, true);

    }
    }

    Thanks,
    Deepak Sharma
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels