Bind Full-Text-Search to custom TextBox?

7 posts, 0 answers
  1. Richard
    Richard avatar
    72 posts
    Member since:
    Feb 2009

    Posted 02 Jun Link to this post

    Is it possible to use a separate TextBox for the full text search? I'd would like to put the search text box in a toolbar on the UI.

    Thanks,
    Richard
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 07 Jun Link to this post

    Hi Richard,

    The whole logic and initialization are inside the GridViewSearchPanel and its DataContext - SearchPanelViewModel. What could be done to get the behavior you want is to display the search panel initially so that the whole initialization logic is triggered and then bind the Text property of the TextBox you want to the SearchText property of the view model. It could be something like: 
    this.clubsGrid.ShowSearchPanel = false;
                var searchPanel = this.clubsGrid.ChildrenOfType<GridViewSearchPanel>().FirstOrDefault();
                this.txtBox.SetBinding(TextBox.TextProperty, new Binding("SearchText") { Source = searchPanel.DataContext, Mode = BindingMode.TwoWay });

    Please give it a try and let me know whether it corresponds to your requirements. 

    Regards,
    Maya
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kirk
    Kirk avatar
    1 posts
    Member since:
    Mar 2015

    Posted 26 Jul Link to this post

    I would also like to know if there is a simple way to bind to the Search Panel TextBox. I have several grids within a tab control that I would like to filter using a value that is bound to a TextBox outside of the tab control. 

    Is this possible?

    Thanks,

    Kirk

  5. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    369 posts

    Posted 27 Jul Link to this post

    Hello Kirk,

    A simple way to achieve the desired behavior would be to handle the TextBox's TextChanged event and update the search criteria there:

    public MainWindow()
    {
        InitializeComponent();
     
        this.txtBox.TextChanged += TxtBox_TextChanged;
    }
     
    private void TxtBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
    {
        var searchPanels = this.ChildrenOfType<GridViewSearchPanel>();
        foreach (var searchPanel in searchPanels)
        {
            (searchPanel.DataContext as SearchViewModel).SearchText = this.txtBox.Text;
        }
    }

    Would such an approach be suitable for your requirements?

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Marcel
    Marcel avatar
    4 posts
    Member since:
    Nov 2015

    Posted 28 Jul in reply to Dilyan Traykov Link to this post

    That does not work directly on the binding data context, you get an exception:

    NullReferenceException: Waarde kan niet null zijn. Parameternaam: source (Value can not be null. Parameter: source)

       bij System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
       bij Telerik.Windows.Controls.GridView.SearchPanel.SearchFilterDescriptorsManager.UpdateFilterDescriptors(List`1 searchValueInfos)
       bij Telerik.Windows.Controls.GridView.SearchPanel.SearchViewModel.set_SearchText(String value)
       bij [Name of app].View.MainWindow.<>c__DisplayClass60_0.<GeneralSearchBox_OnTextChanged>b__1() in [the source file]

     

  7. Marcel
    Marcel avatar
    4 posts
    Member since:
    Nov 2015

    Posted 28 Jul in reply to Marcel Link to this post

    It only works once you have shown the searchbox at least once. (Since then there is something bound to the datacontext).

    Would you know how to fix that without directly binding? To the textfield?

     

    Thanks,

    Marcel

  8. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    369 posts

    Posted 29 Jul Link to this post

    Hello Marcel,

    As stated by my colleague in a previous post, the whole logic and initialization are inside the GridViewSearchPanel and its DataContext - the SearchPanelViewModel.

    So the only way to achieve the desired behavior is to display the search panel initially so that the whole initialization logic is triggered and hide it afterwards if you do not want it being shown.

    Regards,
    Dilyan Traykov
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready