[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

ListView not showing Header or data

I am using VB.Net in VS 2008 . I have never used a ListView control before. I am trying to create a List view with 4 columns and one tag attached to the first column.
When I execute the attached code, I do not receive any errors. However, the ListView control does not display any Headers. The only data displayed is the Employee ID. There are no subitems.
Is my code incorrect? Is there a property of the ListView that I have set incorrectly (the only property I changed was MultiSelect. I changed it to False). Or something else?
Thanks,
pat
Private Sub LoadListView()
        Dim GMFConn As New System.Data.SqlClient.SqlConnection
        Dim GMFCmd As New System.Data.SqlClient.SqlCommand
        Dim GMFReader As System.Data.SqlClient.SqlDataReader
        Dim ParmString As String = ""
        Dim FirstString As String = ""
        Dim LastString As String = ""
        Dim EmpIDNoString As String = ""
        Dim IDNoLong As Long = 0
        Dim CrewString As String = ""
        Dim LineString As String = ""
        Dim ColumnHeaderListView As ColumnHeader
        Dim ListItem As ListViewItem
        '
        Me.lvwEmployee.Clear()
        '
        'Add Header columns
        ColumnHeaderListView = New ColumnHeader
        ColumnHeaderListView.Text = "Employee ID"
        Me.lvwEmployee.Columns.Add(ColumnHeaderListView)
        '
        ColumnHeaderListView = New ColumnHeader
        ColumnHeaderListView.Text = "First Name"
        Me.lvwEmployee.Columns.Add(ColumnHeaderListView)
        '
        ColumnHeaderListView = New ColumnHeader
        ColumnHeaderListView.Text = "Last Name"
        Me.lvwEmployee.Columns.Add(ColumnHeaderListView)
        '
        ColumnHeaderListView = New ColumnHeader
        ColumnHeaderListView.Text = "Crew"
        Me.lvwEmployee.Columns.Add(ColumnHeaderListView)
        '
        ColumnHeaderListView = Nothing
        '
        GMFConn.ConnectionString = GMFConnStringPublic
        GMFConn.Open()
        GMFCmd.Connection = GMFConn
        '
        ParmString = "Select IDNo, EmpIdNo,FirstName, LastName,Crew From GMFEmployee Order by FirstName"
        GMFCmd.CommandText = ParmString
        GMFReader = GMFCmd.ExecuteReader
        Do While GMFReader.Read
            If GMFReader.IsDBNull(0) Then IDNoLong = 0 Else IDNoLong = GMFReader.Item("IDNo")
            If GMFReader.IsDBNull(1) Then EmpIDNoString = "" Else EmpIDNoString = GMFReader.Item("EmpIDNo").ToString.Trim
            If GMFReader.IsDBNull(2) Then FirstString = "" Else FirstString = GMFReader.Item("FirstName").ToString.Trim
            If GMFReader.IsDBNull(3) Then LastString = "" Else LastString = GMFReader.Item("LastName").ToString.Trim
            If GMFReader.IsDBNull(4) Then CrewString = "" Else CrewString = GMFReader.Item("Crew").ToString.Trim
            If Val(EmpIDNoString) > 0 Then
                ListItem = New ListViewItem
                ListItem.Tag = IDNoLong
                ListItem.Text = EmpIDNoString
                ListItem.SubItems.Add(FirstString)
                ListItem.SubItems.Add(LastString)
                ListItem.SubItems.Add(CrewString)
                Me.lvwEmployee.Items.Add(ListItem)
            End If
        Loop
        GMFReader.Close()
        '
        GMFCmd.Dispose()
        GMFConn.Close()
        GMFConn.Dispose()
        ListItem = Nothing
    End Sub

Open in new window

0
mpdillon
Asked:
mpdillon
1 Solution
 
Bob LearnedCommented:
In order to see the columns for a Windows Forms ListView, you need to set the View property to Details.
0
 
lazyberezovskyCommented:
I think ListView.View property of lvwEmployee is Title and you need Details.
0
 
mpdillonAuthor Commented:
The view Property was set to Large Icon. Setting it to Details worked great. Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now