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

Overriding the Default Navigation bahaviour

7 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Orchid Infosys
Top achievements
Rank 2
Orchid Infosys asked on 12 Dec 2010, 08:15 AM

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

Sort by
0
Vanya Pavlova
Telerik team
answered on 13 Dec 2010, 10:32 AM
Hello Fakrudeen,


Please refer to the following blog post.
If you need any further assistance please let me know.

Regards,
Vanya Pavlova
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Orchid Infosys
Top achievements
Rank 2
answered on 17 Dec 2010, 08:42 AM

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

 

 

 

 

0
Veselin Vasilev
Telerik team
answered on 17 Dec 2010, 09:37 AM
Hello 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
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Orchid Infosys
Top achievements
Rank 2
answered on 17 Dec 2010, 12:04 PM
Dear Veselin Vasilev

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
0
Accepted
Veselin Vasilev
Telerik team
answered on 17 Dec 2010, 12:17 PM
Hello 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
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Orchid Infosys
Top achievements
Rank 2
answered on 17 Dec 2010, 01:15 PM

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

0
Veselin Vasilev
Telerik team
answered on 20 Dec 2010, 09:23 AM
Hi 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
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Orchid Infosys
Top achievements
Rank 2
Answers by
Vanya Pavlova
Telerik team
Orchid Infosys
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or