all groups > vb.net controls > october 2005 >
You're in the

vb.net controls

group:

Column width in DataGrid


Column width in DataGrid Jaime Lucci
10/27/2005 12:00:00 AM
vb.net controls:
Hi, how've you been?

How can I do to set the column width of a datagrid to fix the width of the
text in each column?

Thanks.

Jaime Lucci
jaimelucci@hotmail.com

Re: Column width in DataGrid Herfried K. Wagner [MVP]
10/27/2005 12:00:00 AM
"Jaime Lucci" <jaimelucci@hotmail.com> schrieb:
[quoted text, click to view]

5.52 How can I autosize a column in my datagrid?
<URL:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q877q>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Re: Column width in DataGrid Jim Underwood
10/27/2005 12:02:21 PM
This code will not solve your problem entirely, but may put you on the right
track. In my case I had a dozen different data grids and didn't want to
specify the names and widths of every collumn in every one of them so I just
created a function to set all of the collumns to a longer width. It is much
simpler to maintain but doesnt give you as much flexibility.

Public Shared Sub SetTableStyle(ByRef MyDataGrid As DataGrid)

'***********************************************************************
' Public method
' called by all forms using datagrids
' defines consistent table styles in one place

'***********************************************************************
Dim objTableStyle As New DataGridTableStyle
objTableStyle.AlternatingBackColor = System.Drawing.Color.OldLace
'set every other datagrid line to a seperate color to make it easier to read
objTableStyle.PreferredColumnWidth = 150
MyDataGrid.TableStyles.Add(objTableStyle)
End Sub

You can also specify individual collumns, identified by the collumn name in
your dataset. This can be done programatically, or through the TableStyles
Collectin in the designer.


[quoted text, click to view]

AddThis Social Bookmark Button