Column width in DataGrid

J

Jaime Lucci

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
(e-mail address removed)
 
J

Jim Underwood

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.
 

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