Databinding in WinForms performing async data import

Posted by burnside on Stack Overflow See other posts from Stack Overflow or by burnside
Published on 2010-02-24T23:20:06Z Indexed on 2010/05/04 14:58 UTC
Read the original article Hit count: 530

I have a scenario where I have a collection of objects bound to a datagrid in winforms. If a user drags and drops an item on to the grid, I need to add a placeholder row into the grid and kick off a lengthy async import process. I need to communicate the status of the async import process back to the UI, updating the row in the grid and have the UI remain responsive to allow the user to edit the other rows.

What's the best practice for doing this?

My current solution is: binding a thread safe implementation of BindingList to the grid, filled with the objects that are displayed as rows in the grid. When a user drags and drops an item on to the grid, I create a new object containing the sparse info obtained from the dropped item and add that to the BindingList, disabling the editing of that row. I then fire off a separate thread to do the import, passing it the newly bound object I have just created to fill with data. The import process, periodically sets the status of the object and fires an event which is subscribed to by the UI telling it to refresh the grid to see the new properties on the object.

Should I be passing the same object that is bound to the grid to the import process thread to operate on, or should I be creating a copy and merging back the changes to the object on the UI thread using BeginInvoke?

Any problems or advice with this implementation?

Thanks

© Stack Overflow or respective owner

Related posts about databinding

Related posts about winforms