Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

How can I size the width of an unnamed column?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
trint - 31 May 2007 14:31 GMT
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
Nicholas Paldino [.NET/C# MVP] - 31 May 2007 14:38 GMT
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>;

Signature

         - Nicholas Paldino [.NET/C# MVP]
         - mvp@spam.guard.caspershouse.com

> 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
[quoted text clipped - 7 lines]
> Thanks,
> Trint
-pb- - 31 May 2007 14:45 GMT
> 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
[quoted text clipped - 7 lines]
> 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.
trint - 31 May 2007 16:45 GMT
> > 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
[quoted text clipped - 13 lines]
>
> e.g. e.Row.Cells[0].Width = 100.

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.