Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Binding a List<UInt32> object to a DataViewGrid
 

Binding a List<UInt32> object to a DataViewGrid

Hi,
I'm trying to bind a list of simple types (UInt32, double etc.) to a datagridview. I'm using the following simple code:
dataGridView1.DataSource = vectors[0];
vectors is an array of List<UInt32>. Unfortunately, the datagridview appears to be empty though the DataSource property correctly references a list of values.
I've experimented with AutoGenerateColumns and tried to insert columns manually, but the grid insists of not displaying any data.
In all the examples I've seen, the bound data always had a "property name" to reference, but this is not the case here.
Any ideas?
Thanks,
Ury
ury  Wednesday, September 16, 2009 4:16 PM
The grid cannot create columns because there is no bindable properties in datasource items (int in this case).
Implement ITypedList in your datasource, or change your data source type to a collection of objects whose type has properties.


The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
  • Marked As Answer byury Thursday, September 17, 2009 6:14 AM
  •  
Sheng Jiang 蒋晟  Wednesday, September 16, 2009 8:38 PM
Is this a winform DataGridView? If so it may need a binding source. I describe such an action in my example on my blog entitled: C# Linq How To Load a Winform Control Using Dynamic Linq entitites (Or any other Control)
William Wegerson (www.OmegaCoder.Com)
  • Marked As Answer byury Thursday, September 17, 2009 6:14 AM
  •  
OmegaMan  Wednesday, September 16, 2009 4:29 PM
Is this a winform DataGridView? If so it may need a binding source. I describe such an action in my example on my blog entitled: C# Linq How To Load a Winform Control Using Dynamic Linq entitites (Or any other Control)
William Wegerson (www.OmegaCoder.Com)
  • Marked As Answer byury Thursday, September 17, 2009 6:14 AM
  •  
OmegaMan  Wednesday, September 16, 2009 4:29 PM
Thanks William.
I'm not sure regarding the "winform". My app is a VS2005 Windows application.
I added the binding source but the result is the same. Now the binding source object contains 166 items (which is the size of the list object), but the grid is till empty.
Your example refers to names properties. As I said, my list contains ints, doubles etc. (no properties, no names).
Ury
ury  Wednesday, September 16, 2009 4:39 PM
The grid cannot create columns because there is no bindable properties in datasource items (int in this case).
Implement ITypedList in your datasource, or change your data source type to a collection of objects whose type has properties.


The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
  • Marked As Answer byury Thursday, September 17, 2009 6:14 AM
  •  
Sheng Jiang 蒋晟  Wednesday, September 16, 2009 8:38 PM

You can use google to search for other answers

Custom Search

More Threads

• getting error when deleting a row from an MSDE database using datagrid control
• Hide Cell
• Using XML file as a data storage via Typed Dataset
• Master Detail problems.
• Extending DataGridViewTextBoxColumn to DataGridViewHtmlColumn
• Dataset Precision and Scale for Decimal datatype
• How to show a different text for bool (reverse bind)
• dgv issue
• How to remove sorting for one column in Gridview
• Saving the Changes to DB from Datagridview