Listview columns

I have copied and pasted some code to create a listview in VB of my data (sorry I cant actually credit it as I cant remember where I got it) I wanted to add more columns to the example project so added .ColumnHeaders.Add lines for the extra 9 lines needed however they dont seem to appear. I looked through the listview properties but couldnt find an obvious entry for number of columns.  Where am I going wrong with this?
Option Explicit

Private mobjConn                As ADODB.Connection
Private mobjCmd                 As ADODB.Command
Private mobjRst                 As ADODB.Recordset

Private mstrMaintMode           As String
Private mblnFormActivated       As Boolean
Private mblnUpdateInProgress    As Boolean

' Customer LV SubItem Indexes ...
Private Const mlngQ_No_IDX              As Long = 1
Private Const mlngQ_Number_IDX          As Long = 2
Private Const mlngQ_Initiator_IDX       As Long = 3
Private Const mlngQ_Description_IDX     As Long = 4
Private Const mlngQ_PB_IDX              As Long = 5
Private Const mlngQ_Axis_IDX            As Long = 6
Private Const mlngQ_Dead_IDX            As Long = 7
Private Const mlngQ_Position_IDX        As Long = 8
Private Const mlngQ_Delay_IDX           As Long = 9
Private Const mlngQ_Accel_IDX           As Long = 10
Private Const mlngQ_Decel_IDX           As Long = 11
Private Const mlngQ_Speed_IDX           As Long = 12
Private Const mlngQ_CopyCalc_IDX        As Long = 13
Private Const mlngQ_StartPos_IDX        As Long = 14
Private Const mlngQ_TravelDistance_IDX  As Long = 15
Private Const mlngQ_Time_IDX            As Long = 16
Private Const mlngQ_TimeincDelay_IDX    As Long = 17


'*****************************************************************************
'*                          General Form Events                              *
'*****************************************************************************

'-----------------------------------------------------------------------------
Private Sub Form_Load()
'-----------------------------------------------------------------------------
    
    CenterForm Me
    
    ConnectToDB
    
    SetupCustLVCols
    
    LoadCustomerListView
    
End Sub

'-----------------------------------------------------------------------------
Private Sub Form_Activate()
'-----------------------------------------------------------------------------
    
    If mblnFormActivated Then Exit Sub
    
    Refresh
    
    SetFormState True
    
    mblnFormActivated = True

End Sub


'*****************************************************************************
'*                        Command Button Events                              *
'*****************************************************************************


'-----------------------------------------------------------------------------
Private Sub cmdClose_Click()
'-----------------------------------------------------------------------------
    
    Unload Me

End Sub


'-----------------------------------------------------------------------------
Private Sub cmdSave_Click()
'-----------------------------------------------------------------------------

DoCmd.OpenReport "ReportName", acViewPreview

End Sub


'-----------------------------------------------------------------------------
Private Sub cmdCancel_Click()
'-----------------------------------------------------------------------------
    
    mblnUpdateInProgress = False
    SetFormState True
    lvwCustomer_ItemClick lvwCustomer.SelectedItem
    
End Sub



'*****************************************************************************
'*                      Other Control Events                                 *
'*****************************************************************************

Private Sub txtFirst_GotFocus()
    SelectTextboxText txtFirst
End Sub
Private Sub txtLast_GotFocus()
    SelectTextboxText txtLast
End Sub
Private Sub txtAddr_GotFocus()
    SelectTextboxText txtAddr
End Sub
Private Sub txtCity_GotFocus()
    SelectTextboxText txtCity
End Sub
Private Sub txtState_GotFocus()
    SelectTextboxText txtState
End Sub
Private Sub txtState_KeyPress(KeyAscii As Integer)
    If KeyAscii < 32 Then Exit Sub
    If Chr$(KeyAscii) >= "a" And Chr$(KeyAscii) <= "z" Then
        KeyAscii = KeyAscii - 32
    ElseIf Chr$(KeyAscii) >= "A" And Chr$(KeyAscii) <= "Z" Then
        ' OK
    Else
        KeyAscii = 0
    End If
End Sub
Private Sub txtState_Change()
    TabToNextTextBox txtState, txtZip
End Sub

Private Sub txtZip_GotFocus()
    SelectTextboxText txtZip
End Sub
Private Sub txtZip_KeyPress(KeyAscii As Integer)
    KeyAscii = DigitOnly(KeyAscii)
End Sub
Private Sub txtZip_Change()
    TabToNextTextBox txtZip, txtArea
End Sub

Private Sub txtArea_GotFocus()
    SelectTextboxText txtArea
End Sub
Private Sub txtArea_KeyPress(KeyAscii As Integer)
    KeyAscii = DigitOnly(KeyAscii)
End Sub
Private Sub txtArea_Change()
    TabToNextTextBox txtArea, txtPrfx
End Sub

Private Sub txtPrfx_GotFocus()
    SelectTextboxText txtPrfx
End Sub
Private Sub txtPrfx_KeyPress(KeyAscii As Integer)
    KeyAscii = DigitOnly(KeyAscii)
End Sub
Private Sub txtPrfx_Change()
    TabToNextTextBox txtPrfx, txtLine
End Sub

Private Sub txtLine_GotFocus()
    SelectTextboxText txtLine
End Sub
Private Sub txtLine_KeyPress(KeyAscii As Integer)
    KeyAscii = DigitOnly(KeyAscii)
End Sub


'*****************************************************************************
'*               Programmer-Defined Subs & Functions                         *
'*****************************************************************************

'-----------------------------------------------------------------------------
Private Sub ConnectToDB()
'-----------------------------------------------------------------------------

    Set mobjConn = New ADODB.Connection
    mobjConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
                              & "Data Source=" _
                              & GetAppPath _
                              & "Cuesheet Created 20101124 1448.mdb"
    mobjConn.Open

    Set mobjCmd = New ADODB.Command
    Set mobjCmd.ActiveConnection = mobjConn
    mobjCmd.CommandType = adCmdText

End Sub

'-----------------------------------------------------------------------------
Private Sub DisconnectFromDB()
'-----------------------------------------------------------------------------

    Set mobjCmd = Nothing
    
    mobjConn.Close
    Set mobjConn = Nothing

End Sub

'-----------------------------------------------------------------------------
Private Sub SetFormState(pblnEnabled As Boolean)
'-----------------------------------------------------------------------------

    lvwCustomer.Enabled = pblnEnabled
    cmdClose.Enabled = pblnEnabled
    
    
    cmdSave.Enabled = Not pblnEnabled

End Sub

'-----------------------------------------------------------------------------
Private Sub SetupCustLVCols()
'-----------------------------------------------------------------------------
                                 
    With lvwCustomer
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "QNUr", .Width * 0.15
        .ColumnHeaders.Add , , "Q", .Width * 0.09
        .ColumnHeaders.Add , , "Initiator", .Width * 0.05
        .ColumnHeaders.Add , , "Description", .Width * 0.3
        .ColumnHeaders.Add , , "P/B", .Width * 0.02
        .ColumnHeaders.Add , , "Axis", .Width * 0.15
        .ColumnHeaders.Add , , "Dead", .Width * 0.15
        .ColumnHeaders.Add , , "Position", .Width * 0.04
        .ColumnHeaders.Add , , "Delay", 0.04
        .ColumnHeaders.Add , , "Accel", 0.04
        .ColumnHeaders.Add , , "Decel", 0.04
        .ColumnHeaders.Add , , "Speed", 0.04
        .ColumnHeaders.Add , , "Copy Calc", 0.04
        .ColumnHeaders.Add , , "Start Pos", 0.04
        .ColumnHeaders.Add , , "Travel Distance", 0.04
        .ColumnHeaders.Add , , "Time", 0.04
        .ColumnHeaders.Add , , "Time inc delay", 0.04

        
    End With

End Sub

'-----------------------------------------------------------------------------
Private Sub LoadCustomerListView()
'-----------------------------------------------------------------------------
                                 
    Dim strSQL      As String
    Dim objCurrLI   As ListItem
    Dim strZip      As String
    Dim strPhone    As String
    Dim cueno As String
    Dim lngindex As Integer
                                 
    strSQL = "SELECT * FROM Act1 ORDER BY Q"
    
    mobjCmd.CommandText = strSQL
    Set mobjRst = mobjCmd.Execute
    
    lvwCustomer.ListItems.Clear
    
    With mobjRst
                cueno = ""
        Do Until .EOF
            Set objCurrLI = lvwCustomer.ListItems.Add(, , !Qno)
            If cueno = !Qno Then
            objCurrLI.SubItems(mlngQ_No_IDX) = "" & ""
            objCurrLI.SubItems(mlngQ_Number_IDX) = "" & ""
            objCurrLI.SubItems(mlngQ_Initiator_IDX) = "" & ""

            Else
            objCurrLI.SubItems(mlngQ_No_IDX) = !Q & ""
            objCurrLI.SubItems(mlngQ_Number_IDX) = !Initiator & ""
            objCurrLI.SubItems(mlngQ_Initiator_IDX) = !Description & ""
            End If
            objCurrLI.SubItems(mlngQ_Description_IDX) = !PB & ""
            objCurrLI.SubItems(mlngQ_PB_IDX) = !Axis & ""
            objCurrLI.SubItems(mlngQ_Axis_IDX) = !Dead & ""
            objCurrLI.SubItems(mlngQ_Dead_IDX) = !Pos & ""
            objCurrLI.SubItems(mlngQ_Position_IDX) = !Delay & ""
            objCurrLI.SubItems(mlngQ_Delay_IDX) = !Accel & ""
            objCurrLI.SubItems(mlngQ_Accel_IDX) = !Decel & ""
            objCurrLI.SubItems(mlngQ_Decel_IDX) = !Speed & ""
            objCurrLI.SubItems(mlngQ_Speed_IDX) = !CopyCalcTime & ""
            objCurrLI.SubItems(mlngQ_CopyCalc_IDX) = !StartPos & ""
            objCurrLI.SubItems(mlngQ_StartPos_IDX) = !TravelDist & ""
            objCurrLI.SubItems(mlngQ_TravelDistance_IDX) = !MoveTime & ""
            objCurrLI.SubItems(mlngQ_Time_IDX) = !Moveincdelay & ""
   cueno = !Qno
            .MoveNext
        Loop
    End With
   
End Sub

Open in new window

LVL 1
simonwaitAsked:
Who is Participating?
 
EDDYKTCommented:
try to do because 0.04 is too small to see

.ColumnHeaders.Add , , "Delay", 0.04
        .ColumnHeaders.Add , , "Accel", .Width * 0.04
        .ColumnHeaders.Add , , "Decel", .Width * 0.04
        .ColumnHeaders.Add , , "Speed", .Width * 0.04
        .ColumnHeaders.Add , , "Copy Calc", .Width * 0.04
        .ColumnHeaders.Add , , "Start Pos", .Width * 0.04
        .ColumnHeaders.Add , , "Travel Distance", .Width * 0.04
        .ColumnHeaders.Add , , "Time", .Width * 0.04
        .ColumnHeaders.Add , , "Time inc delay", .Width * 0.04

0
 
Brook BraswellApplication Development ManagerCommented:
If you are just wanting to know how many columns...

ListView.ColumnHeaders.Count
0
 
simonwaitAuthor Commented:
Well that returns 17 which is correct - however they listview actually only showing 8 columns.  What I am trying to figure out is if there is something stopping the rest of the columns from displaying.  Below is a screenshot of the resulting view.  It should show all the columns but doesnt

Capture.PNG
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
EDDYKTCommented:
also

.ColumnHeaders.Add , , "Delay", .Width * 0.04
0
 
Brook BraswellApplication Development ManagerCommented:
It looks to me like you are trying to set these columns at a percentage of your width but you left the ".width" out of the remaining headers

so the first 8 columns you have are about 95% of the width of your list view....


 With lvwCustomer
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "QNUr", .Width * 0.15
        .ColumnHeaders.Add , , "Q", .Width * 0.09
        .ColumnHeaders.Add , , "Initiator", .Width * 0.05
        .ColumnHeaders.Add , , "Description", .Width * 0.3
        .ColumnHeaders.Add , , "P/B", .Width * 0.02
        .ColumnHeaders.Add , , "Axis", .Width * 0.15
        .ColumnHeaders.Add , , "Dead", .Width * 0.15
        .ColumnHeaders.Add , , "Position", .Width * 0.04

 ' from here down you left out .width so they have no size...

' hence I add the .Width to give them a better width
        .ColumnHeaders.Add , , "Delay", .Width * 0.04
        .ColumnHeaders.Add , , "Accel", .Width * 0.04
        .ColumnHeaders.Add , , "Decel", .Width * 0.04
        .ColumnHeaders.Add , , "Speed", .Width * 0.04
        .ColumnHeaders.Add , , "Copy Calc", .Width * 0.04
        .ColumnHeaders.Add , , "Start Pos", .Width * 0.04
        .ColumnHeaders.Add , , "Travel Distance", .Width * 0.04
        .ColumnHeaders.Add , , "Time", .Width * 0.04
        .ColumnHeaders.Add , , "Time inc delay",.Width *  0.04

       
    End With

0
 
Brook BraswellApplication Development ManagerCommented:
I do not see the horizontal scroll on your screen shot so I am wondering if you have done something to prevent this from showing - similar to incorrectly setting the column widths
0
 
simonwaitAuthor Commented:
To be honest EDDKYT got there first with the solution however I thought Brook1966's answer explain the reasons better so I though I would give some points to him too.  Gave the second bit of EDDKYT's answer points simply to tie it in with the solution.  Hope this is fair
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.