datagrid Header Center

  • Thread starter Thread starter Jose
  • Start date Start date
Jose,

I use a *HACK* to do it in .NET V1.1

Subclass DataGridColumnStyle and then override its
Alignment and Paint methods

If it's painting a cell you should use the intended aligment.
If it's *not* painting a cell, then it's supposedly painting
the column header, then you should use Center aligment.

<code>
Public Overrides Property Alignment() As
System.Windows.Forms.HorizontalAlignment
Get
If _painting Then
Return MyBase.Alignment ' = intended alignment
Else
'probly painting header?
Return HorizontalAlignment.Center
End If
End Get
Set(ByVal value As System.Windows.Forms.HorizontalAlignment)
MyBase.Alignment = value
End Set
End Property

Protected Overloads Overrides Sub Paint( ... )
_painting = True
MyBase.Paint( ... )
_painting = False
End Sub
</code>

HTH,
Marius.
 
Back
Top