How can I size the width of an unnamed column?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

My columns in dataGridView3 are generated on the fly from a Select
statement, so I can't set up any columns properties before it is
created. Sort of the way I make them visible or not like the
following:
this.dataGridView3.Columns[0].Visible = false; //id
this.dataGridView3.Columns[1].Visible = false; //parent_id

How can I set the width of Columns[3]?
Any help is appreciated.
Thanks,
Trint
 
Trint,

Why not just set the Width property on the DataGridViewColumn returned
from the indexer call to Columns? You are already using the Visible
property, if it is visible, then just set the width:

this.dataGridView3.Columns[3].Visible = true;
this.dataGridView3.Columns[3].Width = <your width here>;
 
My columns in dataGridView3 are generated on the fly from a Select
statement, so I can't set up any columns properties before it is
created. Sort of the way I make them visible or not like the
following:
this.dataGridView3.Columns[0].Visible = false; //id
this.dataGridView3.Columns[1].Visible = false; //parent_id

How can I set the width of Columns[3]?
Any help is appreciated.
Thanks,
Trint

Register for an event called RowDataBound of the grid and in that
event try setting the width of the desired column using
GridViewRowEventArgs event argument.

e.g. e.Row.Cells[0].Width = 100.
 
My columns in dataGridView3 are generated on the fly from a Select
statement, so I can't set up any columns properties before it is
created. Sort of the way I make them visible or not like the
following:
this.dataGridView3.Columns[0].Visible = false; //id
this.dataGridView3.Columns[1].Visible = false; //parent_id
How can I set the width of Columns[3]?
Any help is appreciated.
Thanks,
Trint

Register for an event called RowDataBound of the grid and in that
event try setting the width of the desired column using
GridViewRowEventArgs event argument.

e.g. e.Row.Cells[0].Width = 100.

Thanks Nicholas... this worked:
this.dataGridView3.Columns[3].Width = <your width here>;
Trint
 

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

Back
Top