Menu

#17 Cannot set focused cell in constructor

v4.X
open
nobody
None
2
2007-02-22
2007-02-21
StrFrank
No

Don't know exactly if this is a bug or by design:
After setting grid properties in a form constructor (or in OnLoad event handler as you do in various samples) it's impossible to set the focused cell, to make the default selected cell when the form is created.

How to reproduce:
Try in form sample 14, in the onload event handler add:
grid1.Selection.Focus(5, 0)

Discussion

  • Davide Icardi

    Davide Icardi - 2007-02-22

    Logged In: YES
    user_id=1515232
    Originator: NO

    Unfortunately this is a limitation of the Windows Forms model. The problem is that you cannot set the focus on a control (any windows forms control) before the OnLoad. I suggest to use the first OnActivated event.

    For now I set the bug status to closed because I don't think that there is a way to solve this problem.

     
  • Davide Icardi

    Davide Icardi - 2007-02-22
    • status: open --> closed-rejected
     
  • StrFrank

    StrFrank - 2007-02-22
    • status: closed-rejected --> open-rejected
     
  • StrFrank

    StrFrank - 2007-02-22

    Logged In: YES
    user_id=1346654
    Originator: YES

    I'm aware of the windows forms behaviour (you can solve it also putting code in the OnShow event handler), but I also think it would be very useful to have a way to set the cell that would be initially focused when the form gets open.

     
  • Davide Icardi

    Davide Icardi - 2007-02-22

    Logged In: YES
    user_id=1515232
    Originator: NO

    Ok, I will think if I can find a solution.
    (maybe storing in a variable the last cell that the user want to focus and use it when the grid receive the focus....)

     
  • Davide Icardi

    Davide Icardi - 2007-02-22
    • milestone: --> v4.X
    • priority: 5 --> 2
    • status: open-rejected --> open
     
  • StrFrank

    StrFrank - 2007-02-24

    Logged In: YES
    user_id=1346654
    Originator: YES

    Hi,
    I solved the problem by creating a method SetFocusedCell with this code:

    private void SetSelectedCell(int row, int col)
    {
    if (grid.CanFocus)
    grid.Selection.Focus(new SourceGrid.Position(row, col));
    else
    {
    grid.Selection.Clear();
    grid.Selection.Add(new SourceGrid.Position(row, col));
    }
    }

    Just an idea, but I find this fits my needs.
    Many thank for the help,
    Frank

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.