Click here to Skip to main content
13,398,090 members (32,767 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello All,

What I am trying to achieve is basically to display my calculation results by means of a datagridview control on a form. However, the issue is that the datagridview remains blank when its DataSource = my object. Please see below:

My Object :

   public class PipeDetails

       [CategoryAttribute("Id"), DescriptionAttribute("Id")]
       public string Id { get; set; }

       [CategoryAttribute("Diameter"), DescriptionAttribute("Diameter")]
       public double diameter { get; set; }

       [CategoryAttribute("thickness"), DescriptionAttribute("Coin Thickness")]
       public double thickness { get; set; }

       [CategoryAttribute("ShippedCountry"), DescriptionAttribute("Shipped Country")]
       public string Country { get; set; }

       [CategoryAttribute("pipeName"), DescriptionAttribute("Pipe Name")]
       public List<string> pipeName = new List<string>();

       [CategoryAttribute("pipeCapacity"), DescriptionAttribute("pipe Capacity")]
       public List<double> pipeCapacity = new List<double>();


My Declaration:

public static PipeDetails selectedPipe=new PipeDetails();

The above object is then populated.

Now the issue raised when I implement the following :

private void button1_Click(object sender, EventArgs e)

this.dataGridView3.DataSource= selectedPipe;

Many thanks in advance,

[edit]Code block added - OriginalGriff[/edit]
Posted 20-Nov-12 23:56pm
Updated 21-Nov-12 0:06am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just read this article[^]

under the remarks heading you will see what types the datasource supports and a class I'm afraid isn't one of them.

Also from having a simple test application if you converted the SelectedPipe into a list you will not get the properties that you have set to a list.
Member1978 21-Nov-12 6:29am
Many thanks for your reply. However, issue I have is that I have used two list type variables in my class. If I were to remove the aforementioned then the datagridview works with no issue raised. I am thinking maybe I should re-think about the list variables within my class.
Simon_Whale 21-Nov-12 9:31am
Sadly I dont think there is a way as I know datagridview uses reflection to build up the rows from the datasource.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

update your code as below.
private void button1_Click(object sender, EventArgs e) 
   this.dataGridView3.DataSource= selectedPipe;

This may help you.
Member1978 21-Nov-12 6:26am
Thanks for your suggestion. I should have mentioned. I am using winForm not webForm as a result there is no DataBind() method.
Mohd. Mukhtar 21-Nov-12 6:39am
try to use refresh or update of gridview control.
Member1978 21-Nov-12 7:32am
Many thanks for your help. I use them methods prior to my question. I believe my issue is that I have list variables within my class? If somehow there was a work-around?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

As declared before, the issue was raised due to multiple list<> variables within my class. In order to resolve this, I used DataTable (DataTable dt=new DataTable();). Once this TableData was populated then it was just a matter of implementing the following:

this.dataGridView3.DataSource = dt;

My sincere gratitude go to individuals with their recommendations put forward to this issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180216.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100