Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a application with a datagrid that is written in VB6. I want to edit the width and align(center or right) fields of datagrid. I am unable to.

Can you help me?
Thanks.
Posted
Updated 5-Aug-20 16:13pm
v2

For Width -> DataGrid.Columns(n).Width = 1200

For Aligning -> Since I don't have visual basic 6.0 on my system, I am unable to remember that.
 
Share this answer
 
Doesn't this work?!
VB
DataGrid1.Columns(0).Alignment = dbgCenter
DataGrid1.Columns(0).Alignment = dbgRight
 
Share this answer
 
Comments
ngthtra 19-Dec-10 22:36pm    
thanks!
your code is good, but header row is not Align Center or Align right.i don't know why? You can give a new code to resolve this
thanks
You can try this workaround for alignment of column header.

VB
Dim W As Long
Dim SpaceWidth As Long
Dim NumOfSpaces As Long
Dim ColumnHeaderText As String
ColumnHeaderText = "Hello"
With DataGrid1
  SpaceWidth = Me.TextWidth(" ")
  W = .Columns(1).Width
  NumOfSpaces = (W - Me.TextWidth(ColumnHeaderText)) \ SpaceWidth \ 2
  .Columns(1).Caption = Space$(NumOfSpaces) & ColumnHeaderText
End With


This is what I found on the first link of Google[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900