Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the DataGrid MappingName for a non DataTable DataSource?

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

like image 698
runxc1 Bret Ferrier Avatar asked May 13 '09 18:05

runxc1 Bret Ferrier


People also ask

Which method is used to set data set to Data grid?

At run time, use the SetDataBinding method to set the DataSource and DataMember properties. The following data sources are valid: A DataTable.

What is a DataGrid in c#?

The DataGrid control provides a flexible way to display a collection of data in rows and columns. The DataGrid includes built-in column types and a template column for hosting custom content. The built-in row type includes a drop-down details section that you can use to display additional content below the cell values.

What is DataGridView Data Binding?

The DataGridView control supports the standard Windows Forms data binding model, so it can bind to a variety of data sources. Usually, you bind to a BindingSource that manages the interaction with the data source.


1 Answers

Change:

 tableStyle.MappingName = InventoryItems.ToString();

to

tableStyle.MappingName = InventoryItems.GetType().Name;
like image 80
Chris Brandsma Avatar answered Oct 17 '22 14:10

Chris Brandsma