问题
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