473,320 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

C# App: Binding list of objects to datagridview

3
I thought binding a list of objects using would be a simple as assigning the list to the data source property of the datagridview object on my C# form through Visual Studio 2005. After reading many suggestions on the WEB I've yet to discover the solution.

What I have done is:
1. Added a reference to my CC class
2. In public from and load methods I've included the following line of code.
LIST<CC> CCS NEW = LIST<CC>();
3. In the properties for the datagridview1 I've attempted
a. assigning the list to the data source, this fails as the list is not listed as a data source.
b. assigned the CCS list to the datamember property of the datagridview.


Any Suggestions

LMacd
Nov 26 '07 #1
4 9692
Plater
7,872 Expert 4TB
I don't think a List can be used for a datasource for a datagridview (nothing tells it how to define columns and whatnot) but you should be able to use it has a source for like a DropDown and stuff.

Does your CC class have public properties in the form of:
Expand|Select|Wrap|Line Numbers
  1. pritvate int _myint = 3;
  2. public int Myint
  3. {
  4.    get
  5.    {
  6.       return _myint;
  7.    }
  8. }
  9.  
or similar? This usualy seems to be required to get the object to pick up what values to display.
Nov 26 '07 #2
LMacd
3
Thanks for the headsup on the list.

Since a list cannot be assigned as a data source, I changed directions slightly.
First, I dropped a binding source control onto my form and assigned the business object as the data source.

Then I dropped a binding navigator control onto the form and assigned the binding source control to it.

As a last step I dropped a dataGridView control onto the form and bound the binding source to the datagridview.

The result was a from listing the fields of my business object as headers to the dataGridview.

Unfortunately, when I run this form in debug I'm unable to use any of the add or delete methods listed in the VCR style menu bar.
Nov 27 '07 #3
Frinavale
9,735 Expert Mod 8TB
...
Unfortunately, when I run this form in debug I'm unable to use any of the add or delete methods listed in the VCR style menu bar.
Did you get the GridView to bind properly?
I'm just wondering what a VCR style menu bar is?

-Frinny
Nov 27 '07 #4
LMacd
3
Did you get the GridView to bind properly?
I'm just wondering what a VCR style menu bar is?

-Frinny
First the VCR style bar is just what is displayed when I drop the binding navigator onto the form.

As for binding to the dataGridView I not 100% that I completed the binding correctly. What I did was to click on the databinding arrow and add my binding source. I believe this is what causes the elements in my business object to display at the top.

The work I've complete so far has been by following the articulehttp://msdn2.microsoft.com/en-us/library/ms951295.aspx
written by MikeDub.

Simply dragone from the Toolbox onto your form (bindingsource control) and set its DataSource property to the appropriate list data source, shown in Figure 9. From this sentenced I guess at assigning my business object to the data source, but I must be missing something.

http://msdn2.microsoft.com/en-us/library/ms951295.aspx
Nov 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nathan | last post by:
Hi, I have a datagridview bound to a List of objects (ObjectA). Each ObjectA contains an ObjectB property. Class ObjectA { public ObjectB objB {} }
7
by: Nathan | last post by:
I'd like to use an enumeration as a datasource for a drop-down box. Is there a way to do this?
5
by: ME | last post by:
I have an object we'll call it MyObject. MyObject has a property calld MyBusinessObjects of type List<IMyBusinessObject2>. IMyBusinessObject2 is a defined interface in my application (See below)....
6
by: David Veeneman | last post by:
I am looking for a resource to learn how to do multithreading in a data bound app. So far, I have figured out that I can't update a databound object on a worker thread, because that triggers a...
0
by: Simon Tamman | last post by:
How do other people get around having to define the ValueMember in a DataGridViewComboBoxColumn when binding to a list of business objects? I'm currently doing the following, and it feels wrong...
3
by: =?Utf-8?B?Sm9obiBCdW5keQ==?= | last post by:
New to databinding in vs2005, I always did it manually in 2003. I have no problem loading comboboxes, and a change in that combobox changes the data in the textboxes but I can not figure out a way...
11
by: dave18 | last post by:
Hello all! I found a solution to my original question, but there's still so much I don't understand about it, I thought I'd give this forum a try. At the very least, maybe it will help someone...
1
by: GS | last post by:
I am perplexed . I thought it is easy to fix the binding error on cvtDtFrom. I only used the cvtDtFrom a couple of places but I found out the error occurred before form loading. I tried...
3
by: admlangford | last post by:
Hi, I have a collection of objects which I am storing in a list the object looks like this struct Person { public int age; public string name; }
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.