Adjusting column width of datagrid in windows form (asp.net + C#)

T

Therasa

Hi,
I want to reset the column width of datagrid on runtime. Plz help me
as soon as possible.
 
R

Russ Du Preez

Hi,

Hope this helps!

foreach (DataGridViewColumn column in
dataGridView1.Columns)
{
column.Width = 150;
}

Thanks,
Russ
http://www.cats.co.za
Ultra Rugged, Ultra Reliable Handheld devices
 
R

Russ Du Preez

Sorry got a ahead of myself - Forgot which group I was in!!
You need to add a table style to the DataGrid and You add a
columnstyle for each column - see below:


DataGridTableStyle gridstyle = new DataGridTableStyle();
gridstyle.MappingName = "TableName";
DataGridColumnStyle columnstyle = new DataGridTextBoxColumn();
columnstyle.MappingName = "id";
columnstyle.HeaderText = "Name";
columnstyle.Width = 20;
gridstyle .GridColumnStyles.Add(columnstyle);
dataGrid1.TableStyles.Add(gridstyle );

That should do the trick!

Thanks,
Russ
http://www.cats.co.za
Ultra Rugged, Ultra Reliable Handheld devices
 
T

Therasa

Hi Russ,

Thanks a lot for your sample coding . I have tried this coding but in
my PDA mobile application its not working. if you have any other idea
please send me ASAP.

Thanks in advance.

Regards,
Therasa
 
P

Paul G. Tobey [eMVP]

"Not working" is completely *useless* information. If you want help, you're
going to have to do your part: report accurately on what you did and what
the results were!

Paul T.
 

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