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

Cell focus after edit

2 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Koren
Top achievements
Rank 1
Koren asked on 20 Jan 2012, 05:27 PM
I have some grids where the user selects a code in the first column.  Based on that code, I set some IsReadOnlyBinding MVVM properties to hide or display the rest of the columns.  This works great if the next column is always editable.  However, if the next column is sometimes read only and sometimes editable, I get odd results. 

If I set the default value to editable and then set it to read only when I select the code, that column gets focus although it does not go into edit mode.  I then have to tab again to get to my next editable field.

If I set the default value to hidden and then set it to editable when I select the code, that column gets skipped.  I can tab back to it and it is editable but obviously that is not very user friendly to have to go back and forth.

I know that the keyboard command provider is executed before the property is committed so the next keyboard action is already figured before the grid knows whether the next column is going to be read only or editable.  Is there a way to capture the focus on the cell and move it forward if the cell is read only programmatically?  Or a way to refresh the keyboard commands after the properties are set?  Any other ideas?

thanks!

2 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 25 Jan 2012, 04:10 PM
Hello,

Sorry for the late answer.
With the current version of RadGridView there is no easy way to achieve such behavior. In order to support such scenarios we decided to add new RadGridView built-in command (called CommitCellEdit). The new command will be available with the next internal build (Monday 30 Jan 2012) and then you will be able to meet your goal with a simple KeyboardCommandProvider. For more information about custom keyboard command provider you can take a look at this blog post.

Here is mine CustomKeyboardCommandProvider which works perfectly on my end.

public class CustomKeyboardCommandProvider : DefaultKeyboardCommandProvider
    {
        public GridViewDataControl parentGridView;
 
        public CustomKeyboardCommandProvider(GridViewDataControl grid)
            : base(grid)
        {
            this.parentGridView = grid;
        }
 
        public override IEnumerable<System.Windows.Input.ICommand> ProvideCommandsForKey(System.Windows.Input.Key key)
        {
            List<ICommand> commandsToExecute = base.ProvideCommandsForKey(key).ToList();
            bool shiftIsPressed = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift;
 
            if (key == Key.Tab)
            {
                bool wasInEditMode = this.parentGridView.CurrentCell.IsInEditMode;
                commandsToExecute.Clear();
                commandsToExecute.Add(RadGridViewCommands.CommitCellEdit);
                if (shiftIsPressed)
                {
                    commandsToExecute.Add(RadGridViewCommands.MovePrevious);
                }
                else
                {
                    commandsToExecute.Add(RadGridViewCommands.MoveNext);
                }
                commandsToExecute.Add(RadGridViewCommands.SelectCurrentUnit);
                if (wasInEditMode)
                {
                    commandsToExecute.Add(RadGridViewCommands.BeginEdit);
                }
            }
 
            return commandsToExecute;
        }
    }

All the best,
Nedyalko Nikolov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Koren
Top achievements
Rank 1
answered on 14 Feb 2012, 04:59 PM
Sorry for the even later response back!  I am using a custom keyboard provider already but it has already gone through the keyboard provider by the time it knows whether the next column is read only or not.

If I have three columns, A, B and C.  A is a dropdown which once selected determines whether B is editable or read only.  C is editable.

If I set B as read only by default (using IsReadOnlyBinding) and then change it to editable when A is selected, it skips B and goes to C. (I can back up to B with no problem)

If I set B as editable by default and then change it to read only when A is selected, it stops on B and the user has to tab again to get to C.

I want it to skip B if it is read only and stop on B if it is editable but can't figure out how to do this if it has already gone through the keyboard provider.

thanks!
Tags
GridView
Asked by
Koren
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Koren
Top achievements
Rank 1
Share this question
or