Implement Firefox-like search in WPF application using M-V-VM

I have just submitted my first CodeProject article. You can find it here.

Although I had several article ideas over the years, my laziness prevent me from posting them :)

Hopefully this one will come in handy for those learning and using M-V-VM.


4 comments:

  1. Anonymous

    Hi Miroslav,

    I have been trying to implement your approach for the search at my school's project and having problems.
    Can you help?
    I downloaded the source and understand how it works, but when I am trying to use it in my ClientViewModel i have an error.

    Basically, I have that collection o f Clients that is taken directly from DB (i am using EF). So I return IEnumerable

    then when I try to instantiate Search in the constructor:
    Search = new SearchVM((ICollectionView)ClientsAll, ClientSearchItemMatch);

    where ClientsAll - IEnumerable,

    I have this error:
    "Unable to cast object of type 'System.Data.Objects.ObjectQuery`1[BMB.Data.TBL_CLIENT]' to type 'System.ComponentModel.ICollectionView'."

    Any ideas how I can overcome the problem? Thanks and great job with the search for DataGrid.
    (will keep reading your blog)

    thanks!

     
  2. Miroslav Popovic

    Hi Alex,

    I haven't done much work with EntityFramework (mostly working with NHibernate), but since ObjectQuery implements IEnumerable, there should be an extension method called .ToList() - ClientsAll.ToList().

    If that doesn't work, try to use CollectionViewSource.GetDefaultView(ClientsAll) call - http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.getdefaultview.aspx.

    Thanks,
    Miroslav

     
  3. Anonymous

    Miroslav,

    sorry, i don't know your email, so
    I am communicating through this blog.

    First, thanks for the suggestion.
    Actually converting from IEnumerable to IList resolved by second problem with sorting in datagrid (with ienumerable it didn't work).

    second.. :).. now I am getting a different error in RebuildSearchIndex() :

    Unable to cast object of type 'MS.Internal.NamedObject' to type 'BMB.Data.TBL_CLIENT'.

    any suggestions?
    Thanks for any help

     
  4. Anonymous

    found out that the collection has to be initialized prior to be given as a parameter. false alarm.. thanks!

     

Post a Comment