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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    #1

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

    ..NET 2.0

    I'm wondering if it is possible set the DataGridView.Da taSource to a
    List<objectcoll ection. 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


  • Fred Mertz

    #2
    Re: using List&lt;object& gt; as a datasource, how??

    Suggestion: BindingList<T>




    "Jeff" <donot@spam.mew rote in message
    news:%23vonKuEy HHA.1208@TK2MSF TNGP03.phx.gbl. ..
    .NET 2.0
    >
    I'm wondering if it is possible set the DataGridView.Da taSource to a
    List<objectcoll ection. 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
    >

    Comment

    • Marc Gravell

      #3
      Re: using List&lt;object& gt; as a datasource, how??

      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<Tdoes (**) - this allows
      it to ask for the properties of the type, via TypeDescriptor. And
      better again if it supports the binding interfaces like IBindingList,
      IBindingListVie w - hence BindingList<Tis 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


      Comment

      Working...