Can't clear listview using .items.clear

well the truth is that I can clear the listview but when I go to repopulate the listview I get the new contents plus the old contents.
Private Sub LoadListView()
        ' TODO: Add code to add items to the listview based on the selected item in the treeview
        Dim sql As String = ""
 
        Me.ListView.Items.Clear()
        Me.ListView.BeginUpdate()
 
        Select Case Me.TreeView.SelectedNode.Parent.Text
            Case "FSB"
                sql = "SELECT * FROM tblFSB_TA WHERE Doc_Type ='FSB' AND System = '" & Me.TreeView.SelectedNode.Text & "'"
            Case "TA"
                sql = "SELECT * FROM tblFSB_TA WHERE Doc_Type ='TA' AND System = '" & Me.TreeView.SelectedNode.Text & "'"
            Case "Manuals"
                sql = "SELECT * FROM tblManuals WHERE Doc_Type ='Manual' AND System = '" & Me.TreeView.SelectedNode.Text & "'"
        End Select
 
        'Dim dt As New DataTable
        Dim da As New OleDb.OleDbDataAdapter(sql, OLEConn)
 
        da.Fill(dt)
 
        For Each row As DataRow In dt.Rows
            Dim item As New ListViewItem(row("Doc_Number").ToString())
            item.SubItems.Add(row("Title").ToString())
            If row("Safety") = True Then item.ForeColor = Color.Red
            Me.ListView.Items.Add(item)
        Next
 
        For Each col As ColumnHeader In Me.ListView.Columns
            col.Width = -2
            Application.DoEvents()
        Next
        SetView(View.Details)
        Me.ListView.EndUpdate()
        Me.ToolStripStatusLabel.Text = Me.ListView.Items.Count
    End Sub

Open in new window

NevSoFlyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
>        'Dim dt As New DataTable
>        Dim da As New OleDb.OleDbDataAdapter(sql, OLEConn)

>        da.Fill(dt)

I see you have commented out the DataTable declaration. Have you declared at Class level? If so, you can either create a new DataTable each time you wish to load the ListView, or clear the same DataTable of rows before filling it again....
   
    dt.Rows.Clear()
    Me.ListView.Items.Clear()

Wayne
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NevSoFlyAuthor Commented:
Thank you.  Yes I did declare it at the class level (sorry for not mentioning that) but the dt.rows.clear statement did it.  It seems so simple now.  Agian thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.