Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox Control Text Alignment

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
Does anyone know of a way to change the text alignment for individual columns in a standard MSForms.Listbox control?

-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
Not possible.
You can use a proportional font and pad the front. I would recommend a listview. However with a listview, the first column still must be left justified
 
I do like the listview, but I have never been able to figure out how to make it scroll down when numerous items are added.

-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
must be your style settings, because you should get a scroll bar. Here is a listview that the columns are right justified except for the first. This is done in Access, but the only difference would be the loading.
Code:
Private Sub Form_Load()
  Dim lstItem As ListItem
  Dim lvw As ListView
  Dim rs As DAO.Recordset
  
  Set rs = CurrentDb.OpenRecordset("Suppliers", dbReadOnly)
  Set lvw = Me.lvwOne.Object
  With lvw
     'Set ListView style
     .View = lvwReport
     .GridLines = True
     .FullRowSelect = True
     .Appearance = cc3D
     .TextBackground = lvwOpaque
     
     'Clear Header and ListItems
     .ListItems.Clear
     .ColumnHeaders.Clear
   End With
   'Set up column headers
   With lvw.ColumnHeaders
      .Add , , "Company Name", 2000, lvwColumnLeft
      .Add , , "Contact Name", 2000, lvwColumnRight
      .Add , , "Contact Title", 2000, lvwColumnRight
   End With
   'load from recordset
   Do While Not rs.EOF
     Set lstItem = lvw.ListItems.Add()
     lstItem.Text = rs!CompanyName
     lstItem.SubItems(1) = rs!contactName
     lstItem.SubItems(2) = rs!contactTitle
     rs.MoveNext
    Loop
End Sub
 
MajP,

I appreciate the post, and would like to continue this conversation, but I am tied up with projects at the moment.

-Joshua
Well, You can try banging your head against the wall, but you just end up with lost-time injuries and damaged equipment. [M. Passman]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top