This is a migrated thread and some comments may be shown as answers.

adding a new row and setting focus to it

1 Answer 106 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Subash
Top achievements
Rank 1
Subash asked on 22 Feb 2013, 06:21 PM
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

1 Answer, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 25 Feb 2013, 05:32 PM
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.

Tags
GridView
Asked by
Subash
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Share this question
or