views:

502

answers:

1

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

+4  A: 

Change:

 tableStyle.MappingName = InventoryItems.ToString();

to

tableStyle.MappingName = InventoryItems.GetType().Name;
Chris Brandsma
This is exactly what I was going to write. +1.
Mat Nadrofsky
worked like a charm.
runxc1 Bret Ferrier