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!

Datagrid 2 line header 2

Status
Not open for further replies.

SprintFlunky

Programmer
Apr 6, 2004
51
US
Does anyone know if I can specify a 2 line header in a datagrid. I have a column in a dataset that is a sequence number. I set up my columnstyles and everything works ok, however, the sequence number is only 6 digits long and I waste a lot of width displaying "Sequence Number" as the header. I would like to be able to split the heading to 2 lines.

Any ideas?

Thanks in advance
 
It seems to me that Microsoft really dropped the ball on this one - word wrapping and resizing in the column headers should be built-in functionality. I mean come on, this is an extremely common practice when using datagrids...at least for me it is. Oh well, it will probably be included in the next version of VS .NET as a "feature"...and you and I will only have to pay hundreds of dollars more than we've already spent just to get what amounts to a bug-fix.

For now, you have to work around the problem. Luckily there is what appears to be another bug that allows this:

Code:
Dim dt As DataTable
Dim dc As DataColumn

dc = New DataColumn

dc = New DataColumn
dc.DataType = System.Type.GetType("System.String")
dc.ColumnName = "ColumnName"

dt = New DataTable
dt.Columns.Add(dc)

Dim dr As DataRow

dr = dt.NewRow

dr.Item(0) = "Test 1"

dt.Rows.Add(dr)

DataGrid1.DataSource = dt

Dim f As New System.Drawing.Font(DataGrid1.Font.FontFamily, 15.25F)
DataGrid1.HeaderFont = f

Dim ts As New DataGridTableStyle

ts.MappingName = dt.TableName.ToString

Dim tbc As New DataGridTextBoxColumn
With tbc
    .TextBox.Multiline = False
    .MappingName = "ColumnName"
    .HeaderText = "Column" & vbCrLf & "Name" [green]'<- Here's the word-wrap[/green]
    .Width = 100
End With

ts.GridColumnStyles.Add(tbc)

DataGrid1.TableStyles.Add(ts)

For some reason if you change the header's font to a larger size, it will resize the header row to fit the new font. But if you subsequently apply a custom table style, the header text will not be in the larger font. Put a vbCRLF in the header text where you want the line break and there it is, a word-wrapped header!

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
jebenson,

Worked like a champ - have a star!

Now if the same "feature" works for the printdialog, I'm golden!

Thanks for the solution - I already had the vbCrLf in the header and had no clue why it did not resize. Typical Microsoft.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top