[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Can't clear listview using .items.clear

Posted on 2008-02-03
2
Medium Priority
?
932 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:NevSoFly
2 Comments
 
LVL 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 total points
ID: 20812330
>        '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
 

Author Closing Comment

by:NevSoFly
ID: 31427695
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question