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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing Column Header?

Status
Not open for further replies.

ktchan741

Technical User
Dec 7, 2003
28
SG
Is there anyway to auto-resize the width of a column header?
I have created a data grid using the following:

Dim objTable As DataTable - objDS.Tables(0)
objTable.Columns(0).ColumnName="First Name"
objTable.Columns(1).ColumnName="Last Name"

Upon execution, the column name (i.e. First Name and Last Name) is only shown partially. I need to resize manually by dragging the column header.

I am using vb.net.
Advise appreciated.
 
You'll have to create Table Style, add Column Style to Table Style and add Table Style to DataGrid in order to change column properties. Here's the code

'Bind your DataGrid.
DataGrid1.DataSource = myDataSet.Tables("TableName")

'Create Table Style.
Dim myTS As New DataGridTableStyle

'Set MappingName for TableStyle.
myTS.MappingName = myDataSet.Tables("TableName")

'Create 1st column.
Dim myCOL As New DataGridTextBoxColumn
With myCOL
.MappingName = "ColumnName"
.HeaderText = "HeaderText"
.Width = 100
End With
myTS.GridColumnStyles.Add(myCOL)

'Create 2nd column.
myCOL = New DataGridTextBoxColumn
With myCOL
.MappingName = "ColumnName"
.HeaderText = "HeaderText"
.Width = 200
End With
myTS.GridColumnStyles.Add(myCOL)
..........
..........

'Add TableStyle to the DataGrid.
DataGrid1.TableStyles.Add(myTS)

In case you want to auto-resize Columns, visit the following link





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top