Respond to KeyDown to handle Enter key

3 posts, 1 answers
  1. Pete
    Pete avatar
    67 posts
    Member since:
    Sep 2012

    Posted 11 Jun 2012 Link to this post

    We are using the RadDataFilter as a search criteria control and a radgridview to display the results. At present we have a button, which is associated with a command, that performs the search. 

    Would it be possible to handle the KeyDown event for the filter editors in the DataFilter so that we can fire the command when the used presses enter (ideally, any of the filter editors, but the StringFilterEditor especially)?

    Elsewhere we have used a behavior to associate a command with the KeyDown on a control (and then we fire the command if the key is Enter) , e.g.:
    public class DefaultCommit : Behavior<TextBox> {
      
        protected override void OnAttach() {
            AssociatedObject.KeyDown += OnTextBoxKeyDown;
        }
          
        protected override void OnDetach() {
            AssociatedObject.KeyDown -= OnTextBoxKeyDown;
        }
          
       void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
            {
                if (e.Key == Key.Enter && Command != null)
                {
                    var be = AssociatedObject.GetBindingExpression(TextBox.TextProperty);
                    if (be != null)
                    {
                        be.UpdateSource();
                    }
                    Command.Execute(AssociatedObject.DataContext);
                }
            }
    }

    I have tried using a similar behavior inside the template for the StringFilterEditor, but the binding (using ElementName) doesn't work.
    Is there a way that this can be achieved within the DataFilter control?
    Thanks



  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2012 Link to this post

    Hello,

     You could subscribe for the KeyDown event of the DataFilter itself. Then implement your logic when a key is pressed inside the filtering TextBox.

    Regards,
    Didie
    the Telerik team

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

  3. DevCraft banner
  4. Pete
    Pete avatar
    67 posts
    Member since:
    Sep 2012

    Posted 13 Jun 2012 Link to this post

    Thanks. I've got it working now
Back to Top