Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :


C#
[Serializable()]
   public class PipeDetails
   {

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

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

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


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


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


       [CategoryAttribute("pipeCapacity"), DescriptionAttribute("pipe Capacity")]
       [XmlElementAttribute("pipeCapacity")]
       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 :

C#
private void button1_Click(object sender, EventArgs e)

{
this.dataGridView3.DataSource= selectedPipe;
}


Many thanks in advance,

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 20-Nov-12 23:06pm
v2

Just read this article

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx[^]

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.
 
Share this answer
 
Comments
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.
update your code as below.
C#
private void button1_Click(object sender, EventArgs e) 
{
   this.dataGridView3.DataSource= selectedPipe;
   this.dataGridView3.DataBind();
}

This may help you.
 
Share this answer
 
v2
Comments
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?
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900