什么是数据网格的MappingName对于非数据表的数据源? [英] What is the DataGrid MappingName for a non DataTable DataSource?
问题描述
我能在我的.NET 3.5 CF DataGrid绑定到一个列表(),但我无法通过指定的宽度来格式化列。下面是code,它看起来像它应该工作,但没有。我是pretty的肯定,我不会设置的MappingName正确的,因为所有的教程告诉你,将其设置为你的数据表的名字,但我不是绑定到数据表中,所以我安静不知道该怎么做。
I am able to Bind my DataGrid in .NET 3.5 CF to a List() but I am unable to format the columns by specifying their width. Below is the code that looks like it should work but does not. I am pretty sure that I am not setting the MappingName correctly as all tutorials tell you to set it to the name of your DataTable but I am not binding to a DataTable so I am not quiet sure what to do.
grdBatch.DataSource = InventoryItems;
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = InventoryItems.ToString();
DataGridTextBoxColumn tbcName = new DataGridTextBoxColumn();
tbcName.Width = 400;
tbcName.MappingName = "SERIAL_ID";
tbcName.HeaderText = "SERIAL_ID";
tableStyle.GridColumnStyles.Add(tbcName);
grdBatch.TableStyles.Clear();
grdBatch.TableStyles.Add(tableStyle);
grdBatch是一个DataGrid和InventoryItems是波苏斯列表(平原旧的C#对象)。
grdBatch is a DataGrid and InventoryItems is a List of POCOS(Plain old C# Objects).
推荐答案
修改
tableStyle.MappingName = InventoryItems.ToString();
到
tableStyle.MappingName = InventoryItems.GetType().Name;
这篇关于什么是数据网格的MappingName对于非数据表的数据源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!