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 8055265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:20:05+00:00 2026-06-05T08:20:05+00:00

I have a DataGridView, which has some DataSource. I need to filter the items

  • 0

I have a DataGridView, which has some DataSource. I need to filter the items in the DataGridView, based on some criteria the user specifies.

The problem is that the data is on a very slow database. For many of the items I can filter on information which is stored on the items themselves (which is quick), but sometimes I need to query the database to figure out wether or not a row should be visible.

Hence, I use a BackGroundWorker in the following way:

  1. I make a copy (using CopyTo) of the rows in the DataGridView and pass this to the RunWorkerAsync method
  2. In the DoWork method, I check each of the DataGridViewRow elements in the array. Sometimes I can simply look up the information in the row(E.g. read column 2 on the DataGridViewRow), sometimes I need to query the database.
  3. Each time i know wether or not a row should be visible, I send a tuple consisting of a row number(Simply the position in the passed array of DataGridViewRow elements) and a boolean indicating the visibility to the ReportProgress method, which sets the visibility on the DataGridView.

The reason for copying (using CopyTo) is to avoid accessing the DataGridViews RowCollection from another thread.

All this works fine, but I am really wondering if this is a really bad way to do it.

  • Is it a really bad practice to operate on a RowCollection like this?
  • If it is okay, is it necessary to use CopyTo? The reason I do it is because lists are passed by reference, and I wanted to avoid accessing the UI from a seperate thread.

Thanks for your time.

  • 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-05T08:20:06+00:00Added an answer on June 5, 2026 at 8:20 am

    I think your GUI is too tight to the database for a background worker.

    In general I prefer to use BindingList<T> to bind the grid to, and manipulate the list instead of going through database. But if I have a fairly big amount of data to retrieve from database then I might enable the “virtual mode” of the datagridview, and again make use of the BindingList<T>.

    Hope this helps.

    EDIT1: Of course you can use filtering directly over your DataTables… but then maybe you should not involve the background worker.

    EDIT2: I see BindingList<T> as a chance to bind the view to a model, and not to the data layer directly, which in general is better because separates data layer of presentation layer. Even more, you could create a view-model from the model to bind the grid to (MVVM pattern). But really depends on your project.

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

Sidebar

Related Questions

I have a DataGridView in which one column has data that the user needs
I have a form created which an unbound datagridview that has three columns. Position,
I have a large DataGridView control that has several cells most of which contain
I have a datagridview which is created by various action and user's manipulation of
I have a datagridview in which I want to copy some rows to a
I have a DataGridView which has different rows and columns and it work perfectly
I have a DataGridView bound to a DataTable that has 1+16 columns defined as
My datagridview has a checkbox column that is only valid for some records in
I have a .NET windows app. I have a DataGridView which has a few
Question should be self explanatory. I have a datagridview which has a column whose

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.