Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seting Datagrid preferred column width

Status
Not open for further replies.

bertrandkis

Programmer
Jul 26, 2002
101
ZA
I want to change the width of a data grid that displays a single column of data to 200. This is how I do it:

Me.grdError.TableStyles.Add(New System.Windows.Forms.DataGridTableStyle())

Me.grdError.TableStyles(0).PreferredColumnWidth = 200

Me.grdError.DataSource = dataset1.Tables(0).DefaultView

But the width does not change at all. Can anyone help?
 
Here is how I have changed column widths. It is cumbersome, add columnstyle to a tablestyle to the grid and do it for every column in the bound grid you wish to display:

Dim MyColumnStyle As New DataGridTextBoxColumn()
MyColumnStyle.Width = 200
MyColumnStyle.MappingName = "yourFieldName" 'field name
MyColumnStyle.HeaderText = "Your header text"

Dim MyTableStyle As New DataGridTableStyle()

MyTableStyle.GridColumnStyles.Add(MyColumnStyle )
MyTableStyle.MappingName = "Messages"

Me.grdError.TableStyles.Add(MyTableStyle)

.Refresh()


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top