Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7761989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:16:33+00:00 2026-06-01T14:16:33+00:00

EDIT: I am using VS2008, .NET 3.5 I have a DataTable, which is populated

  • 0

EDIT: I am using VS2008, .NET 3.5

I have a DataTable, which is populated in a DataView and passed into a CollectionView.

   DataTable newLeadTable = new DataTable();
   myConnection.Open();
   dbAdpater.Fill(newLeadTable);
   this.LeadDataView = new DataView(newLeadTable);
   this.LeadsCollectionView = 
   CollectionViewSource.GetDefaultView(this.LeadDataView);

Then the DataGrid that use to display the data is binding to this.LeadsCollectionView

After the user enter the filter text in the View, the ViewModel will execute this method to set the filter string on the DataView:

private void SetLeadListFilter(string LeadFilterStr)
{
  this.LeadDataView.RowFilter = filterString;
}

It works fine, I can see the DataGrid shows proper filtered DataRow.

But then I want to give some UI Experience, add a busy indicator.
So I put the above code into a Thread:

this.IsBusy = true;
Thread filterDataThread= new Thread(new ThreadStart(() =>
{        
    this.LeadDataView.RowFilter = filterString;
    this.IsBusy = false;
}));
filterDataThread.Start();

Now is strange, I can see the code was ran, filter being setted. But the DataGrid doesn’t filter out the rows!

So now I modify the method, reassign the DataView into the CollectionView again:

this.IsBusy = true;
Thread filterDataThread= new Thread(new ThreadStart(() =>
{        
    this.LeadDataView.RowFilter = filterString;
    this.LeadsCollectionView = CollectionViewSource.GetDefaultView(this.LeadDataView); //Added this
    this.IsBusy = false;
}));
filterDataThread.Start();

Now it working! The data is being filter properly on the DataGrid!

So why is this happen when I use threading? Is this the proper way to use DataFilter in Threading?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:16:34+00:00Added an answer on June 1, 2026 at 2:16 pm

    Can’t say for sure, but, as I’ve understand, you use

    CollectionViewSource.GetDefaultView(this.LeadDataView);
    

    to get the Datasource for your DataGrid. Answer is based on this assumption.
    So if you will cal this method outside the filterDataThread, like this:

    this.IsBusy = true;
    Thread filterDataThread= new Thread(new ThreadStart(() =>
    {        
        this.LeadDataView.RowFilter = filterString;
        this.IsBusy = false;
    }));
    filterDataThread.Start();
    this.LeadsCollectionView =  
      CollectionViewSource.GetDefaultView(this.LeadDataView);
    

    then the code with GetDefaultView will probably run before your Thread work – there would be a race between MainThread and filterDataThread, and MainThread wins, and your DataGrid doesn’t filter the data.

    But if you will use the code you’ve provided:

    this.IsBusy = true;
    Thread filterDataThread = new Thread(new ThreadStart(() =>
    {        
        this.LeadDataView.RowFilter = filterString;
        this.LeadsCollectionView =  
          CollectionViewSource.GetDefaultView(this.LeadDataView); //Added this
        this.IsBusy = false;
    }));
    filterDataThread.Start();
    

    the filtering will start in right time.
    So answer is:
    Yes, you are doing the filtering right. But you should add code to handle errors while performing operations in background thread so your application wouldn’t be Busy forever.

    Also, you should check the safe access to the filterString – if you’ll start two or more threads for filtering, there would be another race with unpredictable results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VS2005 ASP.NET 2.0. I have a web application which uses Active
We are using .NET 3.5 with VS2008. I have a solution with ~20 projects
I have a text file that I want to edit using Java. It has
Edit: I am using SqlDataAdapters to fill the data sets. Sorry--I should have been
I have recently been working with Python using Komodo Edit and other simpler editors
I'm using System.Data.Design.TypedDataSetGenerator to convert a .xsd file (generated by VS2008) into a strongly-typed
(VS2005, .Net 2.0) I have a form that is displayed as a dialog using
Using: .NET 3.5SP1, VS2008 I was editting someone else asp.net script, he did the
I have created a setup project with VS2008 for a .NET Windows Forms application
I'm using VS2008, and I have a project that will not start when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.