Vb.net datagrid multiline column header

Hi,
  I am developing a vb.net windows application. I have formatted the datagrid colums using datagridtextboxcolumn . My column headertext  are long . so how to make columnheader multiline?

Sam
sgs1970Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Here is a VB.NET custom DataGrid control, converted from a CodeProject C# control, and modified to have HeaderLines instead of pixels:

' Source:
' http://www.codeproject.com/cs/miscctrl/SizableColumnHdrDataGrid.asp

Imports System.ComponentModel
Imports System.Reflection

Public Class SizableHeaderDataGrid
  Inherits DataGrid

  Private _headerLines As Single = 1.0

  <Description("Get/Set the factor for the scaling the header row"), _
   Category("Layout"), DefaultValue(1.0)> _
  Public Property HeaderLines() As Single
    Get
      Return _headerLines
    End Get
    Set(ByVal Value As Single)
      _headerLines = Value
      OnLayout(New LayoutEventArgs(Me, "HeaderLines"))
    End Set
  End Property  'HeaderLines

  Protected Overloads Overrides Sub OnLayout(ByVal levent As LayoutEventArgs)
    MyBase.OnLayout(levent)
    SetColumnHeaderSize()
  End Sub  'OnLayout

  Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    MyBase.OnPaint(e)
    SetColumnHeaderSize()
  End Sub  'OnPaint

  Private Sub SetColumnHeaderSize()
    If Me.HeaderLines > 0 Then
      Dim [myClass] As New DataGrid
      Dim headerFontHeight As FieldInfo = [myClass].GetType.GetField("headerFontHeight", BindingFlags.NonPublic Or BindingFlags.Instance)
      If Not (headerFontHeight Is Nothing) Then
        Dim height As Int32 = Me.Font.Height * Me.HeaderLines
        If Me.HeaderLines > 1 Then
          headerFontHeight.SetValue(Me, height)
        End If
      End If
    End If
  End Sub  'SetColumnHeaderSize

End Class

'======================================================

After adding this control to your form, just set the HeaderLines property to >1, and put a vbLf to word wrap the header.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sgs1970Author Commented:
I haven't tested as I am with some other assignment. But answers in the past and the profile of Mr.Bob gives me the confidence to accept his answer  without verification

   Thank you,
          Sam
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.