adding a new row and setting focus to it

2 posts, 0 answers
  1. Subash
    Subash avatar
    15 posts
    Member since:
    Dec 2012

    Posted 22 Feb 2013 Link to this post

    hi,
    i want to add a new row to the grid, when the user completes the editing of the last row (i am having 3 columns, in that first two columns only editable, so the user when completes editing the second column focus should be set to the newly added row's second column, so that the user can start typing it.

    In this once i added a new row (when user presses tab after editing last row's second column) focus is moved out of the grid, but the new row is added.

    how can acheive this?

    Thanks
    Subash
  2. Yoan
    Admin
    Yoan avatar
    1182 posts

    Posted 25 Feb 2013 Link to this post

    Hi Subash,

    In order to achieve your goal, you could create your own custom keyboard provider. Please refer to this help article for further details. Then you can predefine the behaviour for the Tab key overriding the ProvideCommandsForKey method similar to:

    public override IEnumerable<ICommand> ProvideCommandsForKey(Key key)
            {
                List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
                if (key == Key.Tab)
                {
                    Club currentItem = parentGrid.CurrentItem as Club;
                    var currentColumn = parentGrid.CurrentColumn;
     
                    if ((currentItem != null) && (parentGrid.Items.IndexOf(currentItem) == (parentGrid.Items.Count-1)) && (currentColumn.DisplayIndex == parentGrid.Columns.Count - 2))
                    {
                        parentGrid.BeginInsert();
                    }
                }
     
                return commandsToExecute;
            }

    For your convinience, I have prepared a sample project that you can find attached.

    I hope this helps.


    Greetings,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top