DataGrid column width.

Please visit this : Samsung Service Galaxy S

I recently found out that the datagrid component doesn`t have the column property. The smartdevice project doesn`t have DataGridView in the toolbox, so you would have to work with the DataGrid componnent.

[All code below is in C#]
At first you must create a DataGridTableStyle :

DataGridTableStyle ts = new DataGridTableStyle();

ts.MappingName = “”;

ts.GridColumnStyles.Clear();
If you have a DataTable to use as a datasource for the grid :

DataTable t = getProduse();

Now if you have to create DataGridColumnStyles for each column in the datatable:

for (int i = 0; i < t.Columns.Count; i++)

{

DataGridColumnStyle Col = new DataGridTextBoxColumn();

Col.MappingName = t.Columns[i].ColumnName;

Col.HeaderText = t.Columns[i].ColumnName;

Col.Width = 400;

ts.GridColumnStyles.Add(Col);

}

After this you add the DataGridTableStyle to the DataGrid:
dataGrid1.TableStyles.Add(ts);
Now when you select the DataSource the grid will have the Style you want:
dataGrid1.DataSource = t;

Commerce Server 2009
By Ing. Msc. Dan Gheorghe

Advertisements
Leave a comment

1 Comment

  1. Louie

     /  March 26, 2012

    Good snipit although you missed a required line at the end:

    ts.MappingName = t.TableName;

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: