简体   繁体   English

DataGrid,C#错误

[英]Error with DataGrid, C#

I am trying to map a list of classes to a datagrid and I am getting a very strange error. 我试图将一个类列表映射到一个数据网格,但遇到一个非常奇怪的错误。 I have a linked list called "AllVars" made up of the following class: 我有一个名为“ AllVars”的链接列表,该列表由以下类组成:

 public class LoggedVariable
        {
            public LoggedVariable()
            {
                Values = new List<float>();
            }
            public List<float> Values { get; set; }
            public string name { get; set; }
            public bool drawn { get; set; }
        }

And there are 8 of these classes, with the values list populated in each, and I am trying to display these values on a datagrid by first mapping them to a DataTable then binding the table to the grid. 这些类中有8个,每个类中都填充了值列表,我试图通过首先将它们映射到DataTable,然后将表绑定到网格,来在数据网格上显示这些值。

        Why = new DataSet();
        GraphData = new DataTable();


        foreach(LoggedVariable element in AllVars)
        {
            GraphData.Columns.Add(element.name);
        }

        for (int t = 0; t < AllVars[0].Values.Count; t++)
        {
            foo = GraphData.NewRow();
            foreach (LoggedVariable element in AllVars)
            {
                foo[element.name] = element.Values[t];
            }
            GraphData.Rows.Add(foo);
        }
        Why.Tables.Add(GraphData);
        LoggedGrid.ItemsSource = Why.Tables[0].DefaultView;

However when I do this, the third, fifth and 7th columns show no data, while the table before mapping it shows that there is data in those columns before mapping it to the data grid...any ideas? 但是,当我这样做时,第三,第五和第七列没有显示任何数据,而映射它之前的表显示了在将它们映射到数据网格之前这些列中有数据……有什么想法吗?

So...The various columns were not being recognized because they had periods at the end of thei r names...Eg 所以...由于各列名称的末尾都有句点,因此无法识别各列...例如

"Test Values for temp." “温度测试值。” <--- These values would not display <---这些值不会显示

"Test Values for temp" <--- These would “温度测试值” <---

Very strange 很奇怪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM