PC Review


Reply
Thread Tools Rate Thread

Binding a IEnumerable list to a DataGridView?

 
 
Jeff
Guest
Posts: n/a
 
      9th Jul 2007
..NET 2.0
VS2005

I'm wondering if it possible to bind an IEnumerable list directly to a
DataGridView? if it is possible then I'm wondering how it should be done?

I ask because I think it must be better to use that, than the implementing a
foreach loop adding a row to the DataGridView for every element in the
IEnumerable list...

Any suggestions?

Jeff


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      9th Jul 2007
You can bind an IList to a DataGridView... full data-binding often
requires random-access. As such, one option is to use
List<SomeType> list = new List<SomeType>(myIEnumerableList);
dataGridView1.DataSource = list;

or alternatively use BindingList<SomeType> if you want notifications
etc

Marc


 
Reply With Quote
 
Sheng Jiang[MVP]
Guest
Posts: n/a
 
      9th Jul 2007
You can use a BindingSource object as the datasource of the grid, and set
the datasource of the bindingsource object to a type. At runtime you can
assign the datasource property of the bindingsource object to a collection
of that type, such as a ReadOnlyCollection or a ObservableCollection object

--
Sheng Jiang
Microsoft MVP in VC++
"Jeff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> .NET 2.0
> VS2005
>
> I'm wondering if it possible to bind an IEnumerable list directly to a
> DataGridView? if it is possible then I'm wondering how it should be done?
>
> I ask because I think it must be better to use that, than the implementing

a
> foreach loop adding a row to the DataGridView for every element in the
> IEnumerable list...
>
> Any suggestions?
>
> Jeff
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding List<T> to a DataGridView = DataGridView Empty admlangford@gmail.com Microsoft C# .NET 3 1st Oct 2008 07:59 AM
Can't bind IEnumerable to DataGridView Ronald S. Cook Microsoft C# .NET 6 20th Feb 2008 10:29 PM
FormatException w/DataGridView when binding to a list of custom o =?Utf-8?B?TmVqYXQ=?= Microsoft Dot NET Framework Forms 5 15th Nov 2006 03:54 PM
Binding IEnumerable derived object squeaky88th Microsoft ASP .NET 0 27th Jun 2003 04:08 PM
Binding IEnumerable derived object squeaky88th Microsoft Dot NET Framework 0 27th Jun 2003 04:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:53 AM.