datagrid Header Center

  • Thread starter Thread starter Jose
  • Start date Start date
J

Jose

Please como center a datagrid header and the data justify to right?

Thanks a lot
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top