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

Enter key transversal

2 Answers 129 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris Coetzee
Top achievements
Rank 1
Chris Coetzee asked on 27 Jun 2012, 07:20 AM
Good day,

We have a GridView and would like to do enter key traversing instead of doing Tab key traversing, when editing a row.
Note that we are using MVVM type architecture.

For a normal grid, the following works fine, but does not seem to work on the telerik RadGridView:

public class EnterKeyTraversal
{
        public static bool GetIsEnabled(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsEnabledProperty);
        }
 
 
        public static void SetIsEnabled(DependencyObject obj, bool value)
        {
            obj.SetValue(IsEnabledProperty, value);
        }
 
 
        static void ue_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            var ue = e.OriginalSource as FrameworkElement;
 
 
            if (ue != null && (e.Key == Key.Enter && ue.GetType() != typeof(Button)))
            {
                e.Handled = true;
                ue.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            }
        }
 
 
        private static void ue_Unloaded(object sender, RoutedEventArgs e)
        {
            var ue = sender as FrameworkElement;
            if (ue == null)
                return;
 
 
            ue.Unloaded -= ue_Unloaded;
            ue.PreviewKeyDown -= ue_PreviewKeyDown;
        }
 
 
        public static readonly DependencyProperty IsEnabledProperty =
                DependencyProperty.RegisterAttached("IsEnabled", typeof(bool),
                typeof(EnterKeyTraversal), new UIPropertyMetadata(false, IsEnabledChanged));
 
 
        static void IsEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var ue = d as FrameworkElement;
            if (ue == null)
                return;
 
 
            if ((bool)e.NewValue)
            {
                ue.Unloaded += ue_Unloaded;
                ue.PreviewKeyDown += ue_PreviewKeyDown;
            }
            else
            {
                ue.PreviewKeyDown -= ue_PreviewKeyDown;
            }
        }
}


Any help would be much appreciated.
Kind regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 27 Jun 2012, 07:37 AM
Hello Chris,

Please take a look at this blog post for a reference on how to implement the functionality that you require.  

All the best,
Maya
the Telerik team

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

0
Chris Coetzee
Top achievements
Rank 1
answered on 27 Jun 2012, 07:53 AM
Should work like a charm. Thank you!
Tags
GridView
Asked by
Chris Coetzee
Top achievements
Rank 1
Answers by
Maya
Telerik team
Chris Coetzee
Top achievements
Rank 1
Share this question
or