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

Respond to KeyDown to handle Enter key

2 Answers 94 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Pete
Top achievements
Rank 1
Pete asked on 11 Jun 2012, 03:33 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 12 Jun 2012, 07:09 AM
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 >>

0
Pete
Top achievements
Rank 1
answered on 13 Jun 2012, 03:01 PM
Thanks. I've got it working now
Tags
DataFilter
Asked by
Pete
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Pete
Top achievements
Rank 1
Share this question
or