• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

microsoft data grid control 6 (OLEDB)

i know how to use this control but only one question
i tried to change the alignment of the fields in this control but only the alignment of the data is changed but the alignment of the header remains as it is. how can i change the alignment of the headers?
0
aft
Asked:
aft
  • 2
1 Solution
 
GrahamSkanRetiredCommented:
This will right-align the heading for the first column


Do
        Me.DataGrid1.Columns(0).Caption = " " & Me.DataGrid1.Columns(0).Caption
Loop Until Me.TextWidth(Me.DataGrid1.Columns(0).Caption) >= Me.DataGrid1.Columns(0).Width

This will centre the heading for the first column

Do
        Me.DataGrid1.Columns(0).Caption = " " & Me.DataGrid1.Columns(0).Caption
        n = n + 1
Loop Until Me.TextWidth(Me.DataGrid1.Columns(0).Caption) >= Me.DataGrid1.Columns(0).Width

Me.DataGrid1.Columns(0).Caption = Space(n/2) & Trim$(Me.DataGrid1.Columns(0).Caption) & Space n/2
0
 
aftAuthor Commented:
but this means that every time i change the width of the column i have to run this code again. there is no direct way through the properties
0
 
GrahamSkanRetiredCommented:
I'm fairly sure there isn't such a property.
However if you also put the code in the grid's ColResize event, it should work automatically. You'll need to trim off the existing spaces, though:
Private Sub DataGrid1_ColResize(ByVal ColIndex As Integer, Cancel As Integer)
Dim n As Integer
Me.DataGrid1.Columns(ColIndex).Caption = Trim$(Me.DataGrid1.Columns(ColIndex).Caption)
Do
       Me.DataGrid1.Columns(ColIndex).Caption = " " & Me.DataGrid1.Columns(ColIndex).Caption
       n = n + 1
Loop Until Me.TextWidth(Me.DataGrid1.Columns(ColIndex).Caption) >= Me.DataGrid1.Columns(ColIndex).Width

Me.DataGrid1.Columns(ColIndex).Caption = Space(n / 2) & Trim$(Me.DataGrid1.Columns(ColIndex).Caption) & Space(n / 2)
End Sub


 
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now