Datagrid and tablestyles

J

Jørgen Fredborg

Hi all

Im loosing my mind here. I am trying to create a datagrid with 2 columns.
The first column must have a width of 50 while the second column must have
width 150.

I cant figure out the relationship between datagrid, datatable, and
tablesstyles.

I have tried this code:

DataTable data = new DataTable();
data.Columns.Add("Date");
data.Columns.Add("Order");

DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = "Order"; <-- What should this be mapped to ?

// Order date column style
DataGridColumnStyle orderDate = new DataGridTextBoxColumn();
shipName.MappingName = "Date";
orderDate.HeaderText = "Date";
orderDate.Width = 50;
ts.GridColumnStyles.Add(orderDate);

// Shipping name column style
DataGridColumnStyle shipName = new DataGridTextBoxColumn();
shipName.MappingName = "Order";
shipName.HeaderText = "Shipping";
shipName.Width = this.Width - orderDate.Width - 37;
ts.GridColumnStyles.Add(shipName);


data.Rows.Add("12-04-2004","Ship no. 1");

DataGrid1.TableStyles.Add(ts);
DataGrid1.DataSource = data;


It doesnt work, Plz help :)
 
P

Peter Foot [MVP]

the MappingStyle property of your DataGridTableStyle should equal the name
of your DataTable - e.g.

DataTable data = new DataTable("MyTableName");
.....
ts.MappingName = "MyTableName";


Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top