Question Create a dynamic DataGridView from a List of objects

mscwd

New member
Joined
Feb 6, 2009
Messages
2
Programming Experience
3-5
Hi,

I am relatively new to C# and winforms, although I have been using Java for years, so forgive me if im asking something relatively straightforward!

I have a DataGridView, it needs to update regularly so I wish to provide a Collection of objects as its DataSource and NOT a database table.

So far I have a List<MyObject> which will be constantly updated via a BackgroundWorker thread. I want my DataGridView to update when a change has been made to the List i.e. if the objects are resorted, added to or deleted from etc.

Currently my DataGridView only displays the first object I add to the List, if I add more the DataGridView doesn't update to display the new objects added.

This is a basic overview of how im coding it:

private List<MyObject> myList= new List<MyObject>();
myDataGridView.DataSource = myList;

Then my BackgroundWorker thread updates the list, e.g.
myList.Add(new myObject);


So how do I tell the DataGridView to update what it displays when a change to the List is made?

Thanks!
 
Try the BindingList(Of T). This is a VB.Net forum site by the way. "VB.NET FORUMS - The Exclusive Visual Basic .NET Community" - get it?
 
Try the BindingList(Of T). This is a VB.Net forum site by the way. "VB.NET FORUMS - The Exclusive Visual Basic .NET Community" - get it?

Woo, thanks John.

BindingList worked a treat.

Why make this a VB.Net only forum? Makes little sense to me ;)

Thanks again!
 
Why make this a VB.Net only forum? Makes little sense to me ;)
Why would you want to use C#? Makes little sense to me, but it is a matter of preference I guess. You should be no short of C# forums on the internet, though. ;) ;)
 
Back
Top