Listbox Columns (1 Viewer)

kirkm

Registered User.
Local time
Tomorrow, 09:03
Joined
Oct 30, 2008
Messages
1,257
I'm getting an error here
Code:
Function ListviewSelect(dat)
    Dim li As ListItem, x As Integer
    With Me.ListView0
        .HideColumnHeaders = True
        .View = lvwReport
        .GridLines = True
        .ListItems.Clear
        .ColumnHeaders.Add , , , 5000
        .ColumnCount = 1           <<<<<<<<<<<<<<<<Error
        .Checkboxes = True
        .FullRowSelect = True
        For x = 0 To UBound(dat)
            Set li = .ListItems.Add(, , dat(x))
        Next
    End With
End Function
Google tells me a listview does have a column count property, but I can't find it. Perhaps only in Excel (or VB) ?
If I rem that out, the listview shows 4 columns and a horizontal scrollbar. I only want one column.
Thanks for any help.
 
Last edited:

kirkm

Registered User.
Local time
Tomorrow, 09:03
Joined
Oct 30, 2008
Messages
1,257
I'd like to know how to fix the columns issue.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:03
Joined
May 21, 2018
Messages
8,527
A listview and listbox are two totally different things. Stop confusing them. There are two entirely different methods to get the counts of the columns.
 

kirkm

Registered User.
Local time
Tomorrow, 09:03
Joined
Oct 30, 2008
Messages
1,257
MajP, could you show the method for setting the number of columns in a listview ?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:03
Joined
May 21, 2018
Messages
8,527
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", 200, lvwColumnRight
      .Add , , "Contact Title", 2000, lvwColumnRight
   End With
   Do While Not rs.EOF
     Set lstItem = lvw.ListItems.Add()
     lstItem.Text = rs!CompanyName
     lstItem.SubItems(1) = rs!contactName
     lstItem.SubItems(2) = rs!contactTitle
     'demo row formatting
     'If rs.AbsolutePosition Mod 2 = 0 Then
     '  lstItem.Bold = True
     'Else
     '  lstItem.ForeColor = RGB(10 * rs.AbsolutePosition, 0, 100 * rs.AbsolutePosition)
     'End If
     rs.MoveNext
    Loop
End Sub
 

kirkm

Registered User.
Local time
Tomorrow, 09:03
Joined
Oct 30, 2008
Messages
1,257
Thanks very much MajP, that was a tremendous help. Seems there's many varieties of Listview and commands differ between them.

All coming togther nicely now. Cheers.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 17:03
Joined
May 21, 2018
Messages
8,527
Seems there's many varieties of Listview and commands differ between them
There are so many way to manipulate a listview, unfortunately there is very little documentation to support it. They are a real PITA to work with.
Why do you need a listview? The work is usually not worth the benefit IMO?
 

Users who are viewing this thread

Top Bottom