Populate unbound DataGridView column from a BackGroundWorker

Posted on 2009-02-24
Last Modified: 2012-05-06
I have an application that shows a large DataGridView full of items.  When the user clicks Search, a stored procedure fills up a local DataTable that is used as the DataSource for the DataGridView.  Then, a BackGroundWorker process is kicked off.  This process goes through each row and sees if there is an image for the item on the file system.  If so, the image is loaded and displayed in an unbound column on the DataGridView.

Here is my dilemma.  How can I accomplish this?  Originally, we didn't use a BackGroundWorker but it tied up the system too long trying to load the items.  There may possibly be several thousand rows.

So we moved the image logic to a BackGroundWorker.  However, we cannot update the UI from here.  I can update it in the ProgressChanged event.  However, how do I know which row to update in the DataGridView?  I don't see a Find option for the DataGridView.  I can search the DataTable, but the image is going to be put in an unbound column so that doesn't seem to help.

I also looked at making the image bound.  I created a new field in the DataTable and tried to manually populate it in the BackGroundWorker.  However, I couldn't figure out what type of DataTable column to create to store the image.

Anyway, that should give an idea of what I'm looking at.  Any ideas on the best way of handling this?

Question by:chlade
    LVL 27

    Assisted Solution

    Instead of finding through the DataGridView, have you tried to find the row in the object the DataGridView is bounded to?


    Author Comment

    The image column wasn't bound.  I tried creating a new column in the datatable and binding with it.  I then populate this in the ProgressChanged event.  The problem is that this hangs the app for some reason for the entire time that the BackGroundWorker is running.  This is the whole reason I'm using it in the first place.  
    LVL 27

    Expert Comment

    I know the image column is unbound, but you asked how to find the row to update, and I was suggesting that you find it through the object behind the DataGridView instead of through the non existing Find option of the DGV you mentioned.

    As to the app hanging, without seeing any code at all, it is virtually impossible to know what is wrong


    Accepted Solution

    I ended up doing the following.  Prior to calling the background worker, I filled a List with the data needed for the background worker.  I filled the list in order from the first row to the last row in the datagridview.  I then passed this List to the backgroundworker.  Then, I had it update the progress after each record was processed.  In doing so, I could just use the row index to update the proper row in the datagridview.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    I'm currently working for a company where I have to upgrade over 50 VB6 programs to VB.NET 2008.  So far I'm about half way through, and I've learned quite a few tricks that drastically improve the performance of VB.NET apps. Because there are a…
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now