What is the DataGrid MappingName for a non DataTable DataSource?
Asked Answered
W

1

5

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).

Washhouse answered 13/5, 2009 at 18:4 Comment(0)
D
15

Change:

 tableStyle.MappingName = InventoryItems.ToString();

to

tableStyle.MappingName = InventoryItems.GetType().Name;
Dedra answered 14/5, 2009 at 23:13 Comment(2)
This is exactly what I was going to write. +1.Compartmentalize
@Chris. The items of collection must implement full property items with private values; not using auto properties, like "public value { get; set;}"Keelung

© 2022 - 2024 — McMap. All rights reserved.