Filter GridView with TextBox, focus issue

6 posts, 1 answers
  1. Nicolas
    Nicolas avatar
    3 posts
    Member since:
    Sep 2012

    Posted 15 Dec 2011 Link to this post

    My scenario:
    I have a simple Telerik GridView and a single Textbox in my WPF App. When I type in the TextBox (FilterBox), I update some FilterDescriptor values and the GridView gets filtered accordingly. 

    What I want to achieve:
    Basically the same behaviour as the Google Chrome Browser in "Search-Mode"; The FilterBox receives all Keyboard presses EXCEPT the arrow keys and "Page Up", "Page Down". Those button presses should be redirected to the GridView, allowing the users to scroll through the filtered results while keeping the focus on the FilterBox (and so allow them to adjust the filter text until they are satisfied with the results). 

    I've tried handling the PreviewKeyDown event of the FilterBox in the following way:

    private void textFilter_PreviewKeyDown(object sender, KeyEventArgs e)
       {
         switch (e.Key)
         {
           case Key.Down:
             {
               e.Handled = true;
               RoutedUICommand moveDownCommand = RadGridViewCommands.MoveDown as RoutedUICommand;
               RoutedUICommand selectCommand = RadGridViewCommands.SelectCurrentUnit as RoutedUICommand;
               moveDownCommand.Execute(null, this.radGridView);
               selectCommand.Execute(null, this.radGridView);
               break;
             }
           case Key.Up:
             {
               e.Handled = true;
               RoutedUICommand moveUpCommand = RadGridViewCommands.MoveUp as RoutedUICommand;
               RoutedUICommand selectCommand = RadGridViewCommands.SelectCurrentUnit as RoutedUICommand;
               moveUpCommand.Execute(null, this.radGridView);
               selectCommand.Execute(null, this.radGridView);
               break;
             }
           default:
             return;
         }
         textFilter.Focus();
        }
    The code works (the up and down arrow keys control the grid), but the FilterBox loses the focus. 

    What do I have to do?
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 16 Dec 2011 Link to this post

    Hello,

     Can you try to execute textFilter.Focus() using Dispatcher? 

    All the best,
    Vlad
    the Telerik team

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

  3. Nicolas
    Nicolas avatar
    3 posts
    Member since:
    Sep 2012

    Posted 16 Dec 2011 Link to this post

    Thanks, that works!

    Just to be complete, I used the following code at the end the PreviewKeyDown method:
    Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
          {
            Keyboard.Focus(textFilter);
          }));
  4. Nick
    Admin
    Nick avatar
    593 posts

    Posted 16 Dec 2011 Link to this post

    Hello Nicolas,

    Yes this will work. You can also do it by textFilter.Focus(). You can reed more about the difference between the two approaches here.

    Kind regards,
    Nik
    the Telerik team

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

  5. Shreya
    Shreya avatar
    18 posts
    Member since:
    Aug 2014

    Posted 16 Feb 2015 in reply to Nicolas Link to this post

    Hi Nicolas,
    I know its very old post but can you tell me how did you updated the gridview results based on text provided in textbox.

    Thanks Much
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Feb 2015 Link to this post

    Hello,

    You can also check our Search As You Type WPF Demo as a reference. It works fine on updating the filtering criteria on each key stroke. 

    Furthermore, you may be interested in the "Filter As You Type With FilterRow" SDK example running it with our SDK Samples Browser

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top