What is the DataGrid MappingName for a non DataTable DataSource?

与世无争的帅哥 提交于 2019-12-01 03:52:38

问题


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 is a DataGrid and InventoryItems is a List of POCOS(Plain old C# Objects).


回答1:


Change:

 tableStyle.MappingName = InventoryItems.ToString();

to

tableStyle.MappingName = InventoryItems.GetType().Name;


来源:https://stackoverflow.com/questions/859464/what-is-the-datagrid-mappingname-for-a-non-datatable-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!