Link to home
Start Free TrialLog in
Avatar of NevSoFly
NevSoFly

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NevSoFly
NevSoFly

ASKER

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.