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
 
Back
Top