A text box that filters a datagrid (search)
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: A text box that filters a datagrid (search)

  1. #1
    Join Date
    Jan 2012

    A text box that filters a datagrid (search)

    Hello everyone, a newbie to Visual studio and programming in general. I use WPF and C#.

    I have a datagrid that shows some observable collection data. I would like to create a search box that filters the datagrid. I have tried something like this

    <UserControl x:Class="Inventar.Views.OpremaListView"

    <CollectionViewSource x:Key="adressSource"
    Source="{Binding AllAdress}">
    <ComponentModel:SortDescription PropertyName="LookupAdress"/>
    <DockPanel Margin="5">
    <Border DockPanel.Dock="Top"
    Style="{StaticResource header}">
    <StackPanel Orientation="Horizontal">
    <TextBlock Text="Oprema ( " />
    <TextBlock Text="{Binding AllAdress.Count}"/>
    <TextBlock Text=")"/>
    <StackPanel DockPanel.Dock="Bottom"
    Style="{StaticResource buttonPanel}">
    <Button Content="Close"
    <DataGrid Margin="5"
    ItemsSource="{Binding Source={StaticResource adressSource}}"

    <Button Style="{StaticResource openButton}"/>
    <DataGridTextColumn Header="Inventurni Broj" Binding="{Binding InventurniBroj}" />
    <DataGridTextColumn Header="Naziv" Binding="{Binding Naziv}" />
    <DataGridTextColumn Header="Dobavljac" Binding="{Binding Dobavljac}" />
    <DataGridTextColumn Header="Zaduzio" Binding="{Binding Adress.Contact.Zaduzio}" />
    <DataGridTextColumn Header="Vrijednost" Binding="{Binding Vrijednost}" />



    While the search code is this

    public void Search(string criteria)
    if (!string.IsNullOrEmpty(criteria) && criteria.Length > 2)
    CurrentAdress = new ObservableCollection<Adress>(

    StatusText = string.Format("{0} zaduzenih pronađeno.", CurrentAdress.Count);
    CurrentAdress = new ObservableCollection<Adress>(_adressRepository.FindAll());
    StatusText = "Prikaz svih zaduzenih.";

    But it doesn't work. Any ideas?

  2. #2
    Join Date
    Jan 2012

    Re: A text box that filters a datagrid (search)

    Is there no one who has any ideas on how to solve this problem?

  3. #3
    Join Date
    Jan 2012

    Re: A text box that filters a datagrid (search)

    Ok so my latest news is that the search works but the data grid does not refresh as I type into the search box. I have to turn off the tab that I open and then turn it back on for the search to show up on the grid.

    Anyone out there with ideas on how to do this? Keep in mind that I use the Model View Presenter pattern so my search box is a user control while my grid is a View.

    Please people help me.

  4. #4
    Join Date
    Feb 2012

    Re: A text box that filters a datagrid (search)

    I am fairly new to WPF and MVVM also, but I ran into the same problem you did and thought I could suggest you try what I did. You can move your collectionviewsource which you call addressSource to your viewmodel and and then calle addressSource.Refresh() at the end of your search function. Let me know if that works for you. Perhaps we could help each other learn WPF and MVVM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)