locked
How to filter ef data displayed in datagridview RRS feed

Answers

All replies

  • On 2/23/2012 10:26 AM, markev wrote:
    > Hi
    >
    > I'm trying to filter the data from EF that is displayed in a vb winforms
    > datagrid view. I don't want to run another query against the database -
    > is there a simple way to achieve it. In my current app the I use the
    > keypressed event on a textbox to apply a filter to the datasource, but
    > nothing seems to happen:( I have included a link to the app below.)
    >
    >
    > Any help much appreciated.
    >
     
    If it was me, then I would return the original query in a List<t> in
    memory. Then I would query the List<t> binding the results to the
    control. That way, you can query the List<t> with filters not having to
    go back to that database.
     
     
    • Marked as answer by Allen_MSDN Monday, March 5, 2012 2:34 AM
    Thursday, February 23, 2012 6:13 PM
  • Hi markev,

    Welcome to MSDN Forum.

    I agree with @darnold924, if the data are not very huge, you can load all the data into memory and filter in the memory. Without hitting the database everytime, the performance may be better.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, February 27, 2012 2:39 AM
  • Clearly I'm missing something - have tried loading it into a list and binding the list to the datasource as below

            itemslist = dbcontext.items.Local
    
    
            'ItemBindingSource.DataSource = dbcontext.items.Local.ToBindingList
            ItemBindingSource.DataSource = itemslist

    Using this, I can't sort or filter the datagridview.

    Mark

    Monday, February 27, 2012 12:17 PM
  • Hi markev,

    List(T) class has many methods which support to sort and filter, please refer to the link and choose the proper methods for you.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Monday, March 5, 2012 2:34 AM
    Tuesday, February 28, 2012 2:52 AM