表格上的Datagridview控件保持空白 [英] Datagridview control on the form remains blank

查看:121
本文介绍了表格上的Datagridview控件保持空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想要实现的基本上是通过窗体上的datagridview控件显示我的计算结果.但是,问题在于,当datagridview的DataSource = my对象时,datagridview仍为空白.请参见以下内容:

我的对象:


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 :


[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>();

   }



我的宣言:

公共静态PipeDetails selectedPipe =新PipeDetails();

然后将填充上面的对象.

现在,当我实现以下内容时出现了问题:



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;
}



在此先感谢,

[edit]已添加代码块-OriginalGriff [/edit]



Many thanks in advance,

[edit]Code block added - OriginalGriff[/edit]

推荐答案

只需阅读本文

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

在备注标题下,您将看到数据源支持的类型,而且我担心的类也不是其中之一.

同样,如果将SelectedPipe转换为列表,则只有一个简单的测试应用程序,您将不会获得已设置为列表的属性.
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.


按如下所示更新代码.
update your code as below.
private void button1_Click(object sender, EventArgs e) 
{
   this.dataGridView3.DataSource= selectedPipe;
   this.dataGridView3.DataBind();
}



如前所述,由于存在多个list<> ;,因此引发了该问题.我班上的变量.为了解决这个问题,我使用了DataTable(DataTable dt = new DataTable();).填充此TableData之后,只需执行以下操作即可:

this.dataGridView3.DataSource = dt;


我衷心感谢个人对这个问题提出的建议.
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.


这篇关于表格上的Datagridview控件保持空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆