ListView Not Displaying

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I've been unsuccessful trying to get my ListView to display. The code is from other successful populations of ListViews. While Debugging I've determined that the sqlDataReader is correctly reading the data and that the ListView is being added to the collection. This has got to be something simple but I can't find it. Any help would be appreciated.

VB.NET:
        With Me.navListView
            .BeginUpdate()
            .View = Windows.Forms.View.Details
            .GridLines = False
            .FullRowSelect = True
            .MultiSelect = True
            .BorderStyle = BorderStyle.FixedSingle
            .Columns.Add("SPR", 100, HorizontalAlignment.Left)
            .Columns.Add("Project", 100, HorizontalAlignment.Left)
            .Columns.Add("Title", 100, HorizontalAlignment.Left)
            sqlString = "SELECT Application, ProblemID, Title FROM tblProblems WHERE " _
                & classText & " = '" & itemText & "' ORDER BY Application, ProblemID"
            Me.navListView.Clear()
            Using Cnn As New SqlClient.SqlConnection(My.Settings.ProbSQLConnectionString.ToString)
                Using Cmd As New SqlClient.SqlCommand(sqlString, Cnn)
                    Cnn.Open()
                    Using dr As SqlClient.SqlDataReader = Cmd.ExecuteReader
                        While dr.Read
                            Dim ListItem As New ListViewItem(dr("ProblemID").ToString())
                            ListItem.SubItems.Add(dr("Application").ToString)
                            ListItem.SubItems.Add(dr("Title").ToString)
                            Me.navListView.Items.Add(ListItem)
                        End While
                    End Using
                End Using
            End Using
            .EndUpdate()
        End With
 
Last edited by a moderator:
VB.NET:
            .Columns.Add("SPR", 100, HorizontalAlignment.Left)
            .Columns.Add("Project", 100, HorizontalAlignment.Left)
            .Columns.Add("Title", 100, HorizontalAlignment.Left)
[B]            Me.navListView.Clear()[/B]
ListView.Clear() also clears columns, you probably want ListView.Items.Clear()
Or clear full listview before adding columns & items...
 
Back
Top