Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Vb.net datagrid multiline column header

Posted on 2006-04-11
2
Medium Priority
?
2,122 Views
Last Modified: 2009-12-16
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
0
Comment
Question by:sgs1970
2 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 16435795
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
 

Author Comment

by:sgs1970
ID: 16467255
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Loops Section Overview
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question