microsoft data grid control 6 (OLEDB)

Posted on 2003-03-19
Medium Priority
Last Modified: 2008-02-26
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?
Question by:aft
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 76

Accepted Solution

GrahamSkan earned 100 total points
ID: 8165414
This will right-align the heading for the first column

        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

        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

Author Comment

ID: 8179792
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
LVL 76

Expert Comment

ID: 8180230
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)
       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


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month12 days, left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question