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

Filter GridView with TextBox, focus issue

5 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nicolas
Top achievements
Rank 2
Nicolas asked on 15 Dec 2011, 05:12 PM
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?

5 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 16 Dec 2011, 10:42 AM
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 >>

0
Nicolas
Top achievements
Rank 2
answered on 16 Dec 2011, 05:27 PM
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);
      }));
0
Nick
Telerik team
answered on 16 Dec 2011, 05:52 PM
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 >>

0
Shreya
Top achievements
Rank 1
answered on 16 Feb 2015, 02:05 PM
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
0
Dimitrina
Telerik team
answered on 18 Feb 2015, 09:52 AM
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.

 
Tags
GridView
Asked by
Nicolas
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Nicolas
Top achievements
Rank 2
Nick
Telerik team
Shreya
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or