0

Trying to add a filter for the list. I have a textbox and an event that does this when the textbox text changes:

        this.objectListView1.ModelFilter = TextMatchFilter.Contains(this.objectListView1, filterString.Text);

When I key in a character into the textbox I am getting the following error:

    System.ObjectDisposedException: 'The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.'

I am using Entity Framework to get the data for the list view. I fill my data when the form with the listview loads using a method for that.

What is causing the error? How do I correct this?

Eric Snyder
  • 1,816
  • 3
  • 22
  • 46
  • Do you have any event handlers set up e.g. `SelectedIndexChanged` that might get fired (and crash) when the filter applies and changes the selected object? Do you have a stack trace for the Exception? Are the objects in the tree objects fetched from the database? It could be related to this if you have Aspects that use navigation properties (https://stackoverflow.com/questions/18398356/solving-the-objectcontext-instance-has-been-disposed-and-can-no-longer-be-used) – Thomas N Apr 16 '19 at 06:58
  • 1
    @Thomas N - Thanks. That was the clue I needed. The objects are fetched from a database using Entity Framework. They are lazy loading. I changed my logic (I am sure there would be a better way) to transfer the anonymous data type to a list and then I use the list to objectListView1.SetObjects(myList);. There is probably a smarter way to get the Entity Framework result to eager loading. I'll work on that later ;). – Eric Snyder Apr 16 '19 at 18:03

0 Answers0