using List<object> as a datasource, how??

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

..NET 2.0

I'm wondering if it is possible set the DataGridView.DataSource to a
List<object> collection. Where object is a class derived from the object
class.

If it's possible then my question is how?

I ask becasue I think it's much better to use the collection directly than
performing a foreach statement adding the rows to the DataGridView...

any suggestions?

Jeff
 
Any list (IList (*)) can be used as a data source, even plain
ArrayList. The binding works much better if the collection implements
a typed indexer "T this[int]", which List<T> does (**) - this allows
it to ask for the properties of the type, via TypeDescriptor. And
better again if it supports the binding interfaces like IBindingList,
IBindingListView - hence BindingList<T> is your best bet (as per
Fred's post).

Just some background.

[* aside: or something that exposes a list via IListSource]
[** aside: ITypedList performs a similar role to a typed indexer, but
is more complex to implement]

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top