Advertisement

07.08.2008 at 05:48AM PDT, ID: 23546381
[x]
Attachment Details

Losing items in a ListView on clear

Asked by EGormly in Microsoft Visual Basic.Net, Visual Studio .NET 2005

Visual Studio 2005
Visual Basic.net
Windows Application

I have a ListView, it is populated by a directory file list.
I change a filename, clear list, refresh and repopulate but it will not update.

My Method is the following:
User Starts program
User Selects a directory to work with
The ListView is populated with file names from the selected drirectory
The user enters search for text into a text box
The user enters replace text into a replace box
The User presses a "replace" button.
The List is updated with any changes.

Everything works except for the updating of the listview.



Form Load Code:

        MyPath = "C:\testfolder\"
        Dim dir As New DirectoryInfo(MyPath)

'Note: I have 4 listview colums set up in the design time columns collection if that makes a difference.

        ListView1.View = View.Details
        ListView1.FullRowSelect = False
        For Each file As FileInfo In dir.GetFiles()
            Dim item As New ListViewItem(file.Name)
            item.SubItems.Add(file.Name)
            item.SubItems.Add(file.LastWriteTime)
            item.SubItems.Add(file.CreationTime)
            ListView1.Items.Add(item)
        Next

Button Click:
     ListView1.clear
   ' Replace Code
   ' and other stuff here

   ' Refresh the List view with newly named files of the selected directory.
        ListView1.View = View.Details
        ListView1.FullRowSelect = False
        For Each file As FileInfo In dir.GetFiles()
            Dim item As New ListViewItem(file.Name)
            item.SubItems.Add(file.LastWriteTime)
            item.SubItems.Add(file.CreationTime)
            ListView1.Items.Add(item)
        Next

When I run the the list view is blank.
If I do not use "ListView1.Clear" I just get the same items added to the ListView
so I know the code is working, but it is the ListView.Clear that is messing things up.
I assume I have to rebuild the ListView or something?



Maybe I am doing it wrong?  Start Free Trial
[+][-]07.08.2008 at 06:13AM PDT, ID: 21953406

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 06:24AM PDT, ID: 21953521

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.08.2008 at 06:25AM PDT, ID: 21953528

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Visual Studio .NET 2005
Sign Up Now!
Solution Provided By: FernandoSoto
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.08.2008 at 06:41AM PDT, ID: 21953680

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628