Hai
How do I override the default behaviour of navigating cells downwards upon Enter Key Press, I want to navigate towards right and upon reaching last cell of last row, a new Row should be created.
customer ID jx413597
7 Answers, 1 is accepted
Please refer to the following blog post.
If you need any further assistance please let me know.
Regards,
Vanya Pavlova
the Telerik team
Hello Vanya Pavlova
Thanks for your reply, I referred to the blog you suggested, I got the idea and tried to implement my logic and almost succeeded.
I need a little bit more help from you to completely solve it.
Below is what I am trying to achieve :-
If it is the last Column of the last Row then I need to create a new Row and Begin Insert from its First Column, it works but rather than going to the First Column it goes to the last Column of the New Row.
The other two conditions works perfectly. Please help.
if
(parentGrid.CurrentCell.IsInEditMode)
{
if (IsLastRow() & IsLastCell())// Last Column and Last Row
{
commandsToExecute.Clear();
commandsToExecute.Add(RadGridViewCommands.BeginInsert);
}
else if (IsLastCell()) // Last Column but not Last Row
{
commandsToExecute.Clear();
commandsToExecute.Add(RadGridViewCommands.MoveNext);
commandsToExecute.Add(RadGridViewCommands.BeginEdit);
}
else
{
commandsToExecute.Clear();
commandsToExecute.Add(RadGridViewCommands.MoveRight);
commandsToExecute.Add(RadGridViewCommands.BeginEdit);
}
}
With Regards
Fakrudeen
Please try this one:
class
CustomKeyboardCommandProvider : DefaultKeyboardCommandProvider
{
private
GridViewDataControl parentGrid;
private
DefaultKeyboardCommandProvider defaultKeyboardProvider;
private
CustomKeyboardCommandProvider customKeyboardProvider;
public
CustomKeyboardCommandProvider(GridViewDataControl grid)
:
base
(grid)
{
this
.parentGrid = grid;
}
public
override
IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
List<ICommand> commandsToExecute =
base
.ProvideCommandsForKey(key).ToList();
if
(key == Key.Enter)
{
commandsToExecute.Clear();
var lastItem =
this
.parentGrid.Items[
this
.parentGrid.Items.Count - 1]
as
Club;
var lastColumn =
this
.parentGrid.Columns[
this
.parentGrid.Columns.Count - 1]
as
Telerik.Windows.Controls.GridViewColumn;
if
(
this
.parentGrid.CurrentItem == lastItem &&
this
.parentGrid.CurrentColumn == lastColumn)
{
commandsToExecute.Add(RadGridViewCommands.BeginInsert);
}
else
if
(
this
.parentGrid.CurrentColumn == lastColumn)
{
commandsToExecute.Add(RadGridViewCommands.MoveDown);
commandsToExecute.Add(RadGridViewCommands.SelectCurrentUnit);
commandsToExecute.Add(RadGridViewCommands.SelectCurrentItem);
}
else
{
commandsToExecute.Add(RadGridViewCommands.MoveRight);
}
}
return
commandsToExecute;
}
}
Regards,
Veselin Vasilev
the Telerik team
Thanks for your reply, but the code doesn't seem to solve the problem, still when Enter is pressed up one reaching the Last Cell of Last Row, new Row is inserted but the cursor is in the Last Cell of the New Row, it doesn't go to the First Cell.
Regards
Fakrudeen
Here is the modified code:
public
override
IEnumerable<ICommand> ProvideCommandsForKey(Key key)
{
List<ICommand> commandsToExecute =
base
.ProvideCommandsForKey(key).ToList();
if
(key == Key.Enter)
{
commandsToExecute.Clear();
var lastItem =
this
.parentGrid.Items[
this
.parentGrid.Items.Count - 1]
as
Club;
var lastColumn =
this
.parentGrid.Columns[
this
.parentGrid.Columns.Count - 1]
as
Telerik.Windows.Controls.GridViewColumn;
if
(
this
.parentGrid.CurrentItem == lastItem &&
this
.parentGrid.CurrentColumn == lastColumn)
{
this
.parentGrid.CurrentColumn =
this
.parentGrid.Columns[0];
commandsToExecute.Add(RadGridViewCommands.BeginInsert);
}
else
if
(
this
.parentGrid.CurrentColumn == lastColumn)
{
commandsToExecute.Add(RadGridViewCommands.MoveDown);
commandsToExecute.Add(RadGridViewCommands.SelectCurrentUnit);
commandsToExecute.Add(RadGridViewCommands.SelectCurrentItem);
}
else
{
commandsToExecute.Add(RadGridViewCommands.MoveRight);
}
}
return
commandsToExecute;
}
Also, please set the IsSynchronizedWithCurrentItem property of the gridview to True.
Kind regards,
Veselin Vasilev
the Telerik team
Thanks Veselin Vasilev, it works now.
How do I access the values entered by the user in the Cell from with in this method
(ProvideCommandsForKey(Key key)). suppose I need to know whether some value is entered in the First Cell of the Newly created Row, and if no Value is entered then I need to cancel the New Row.
ie call commandsToExecute.Add(RadGridViewCommands.CancelRowEdit); Thanks.
Regards
Fakrudeen
Probably the better approach would be to subscribe to the CellEditEnded or RowEditEnded events in this case.
Let me know if I am missing something.
Greetings,
Veselin Vasilev
the Telerik team