NJ5J: datagrid - setting column widths

G

Guest

I have been trying to set the column widths on a datagrid using Styles but to
no avail.
When I load my datagrid with SQL Server CE data the cell widths are all
constant and too small in width. This forces the user to drag them larger -
I want to set the column widths individually so the user does not have to do
this.
My attempts to use styles has failed - and width appears to be valid for the
..net compact framework according to documentation.
Carl Perkins (e-mail address removed)
 
S

Sergey Bogdanov

Use DataGridTableStyle together with DataGridColumnStyle to set a width
for each column. Here is a small example how it can be done:

DataGridTableStyle dgts = new DataGridTableStyle();
dgts.MappingName = "TableName";

DataGridColumnStyle c = new DataGridTextBoxColumn();
c.MappingName = "FielName";
c.HeaderText = "Field";
c.Width = 100;
dgts.GridColumnStyles.Add(c);

dataGrid1.TableStyles.Add(dgts);


Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
G

Guest

Sergey,
That worked superbly!
THANK YOU!
THANK YOU!
THANK YOU!
Carl Perkins
(e-mail address removed)
 

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