Formatting DataGridView headers?

NetDog

Member
Joined
Feb 28, 2008
Messages
9
Programming Experience
1-3
Although as a VB newbie I know that I can format DataGridView columns via the properties options. But, I don't know how to format the column headers.

Right now I need to have certain column headers right-aligned for columns containing money.

Can someone please point me in the right direction?
 
Many thanks for that MattP - much appreciated.

Can Columns(0) be more than one as in Columns(0,3,5)? (I don't have VB on this box to try right now)
 
You're not able to specify the columns in that way but you should be able to provide the columns in an array and apply the formatting in a For loop.

VB.NET:
Dim MoniesColumns() As Integer = {0, 3, 5}

For i As Integer = 0 To MoniesColumns.Length - 1
    Me.MyDataGridView.Columns(MoniesColumns(i)).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
Next
 
Back
Top