Set Alignment of Specific DatagridView Column Header in

I was struggling with this yesterday. Probably an easy thing for some of you folks. But here is what I came up with.

Private Sub DataGridView1_ColumnHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.ColumnHeaderMouseClick
       ‘apply the sorting to the 4th column only
       If e.ColumnIndex = 3 Then
           With DataGridView1
               If .Columns(e.ColumnIndex).HeaderText.Substring(0, 1) = "^" Then
                   .Sort(.Columns(e.ColumnIndex), System.ComponentModel.ListSortDirection.Ascending)
                   .Columns(e.ColumnIndex).HeaderText = "v PruSaver"
                   .Sort(.Columns(e.ColumnIndex), System.ComponentModel.ListSortDirection.Descending)
                   .Columns(e.ColumnIndex).HeaderText = "^ PruSaver"
               End If
           End With
       End If
   End Sub

Consulting Requests


Blog Front Page

Technorati Tags: ,,,,,,,,,,,,

Windows Live Tags:,.NET Framework,csharp,Alignment,Specific,DatagridView,Column,Header,ColumnHeaderMouseClick,HeaderText,Sort,ComponentModel,ListSortDirection

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: