Results 1 to 3 of 3

Thread: [RESOLVED] csv file from two listveiw

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    74

    Resolved [RESOLVED] csv file from two listveiw

    I use this code to produce a csv file from a listview...

    can someone help me do some tweaks on the code to enable me to produce a csv from lvChecked and from another listview. It would be like merging the contents of two listview in a single csv file.

    Code:
     SaveFileDialog1.ShowDialog()
            Using csvFile As New System.IO.StreamWriter(SaveFileDialog1.FileName + ".csv")
                For Each lstItem As ListViewItem In lvChecked.Items
                    csvFile.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", lstItem .Text, lstItem .SubItems(0).Text, lstItem .SubItems(1).Text, lstItem .SubItems(2).Text, lstItem .SubItems(3).Text, lstItem .SubItems(4).Text, "MISSING", Format(Now, "dd/MM/yyyy")))
                Next
                MessageBox.Show("Successful")
            End Using
    Thank you so much!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: csv file from two listveiw

    You would simply put two loops inside your Using statement. Or do you mean that you want one line of the file to contain data from both ListViews? If so then use a For loop rather than For Each. That way you can index both ListView.Items collections in the one loop.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2013
    Posts
    74

    Re: csv file from two listveiw

    Thanks jmcilhinney, this one did the trick

    Code:
    SaveFileDialog1.ShowDialog()
            Using csvFile As New System.IO.StreamWriter(SaveFileDialog1.FileName + ".csv")
                For Each lstItem As ListViewItem In lvChecked.Items
                    csvFile.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", lstItem .Text, lstItem .SubItems(0).Text, lstItem .SubItems(1).Text, lstItem .SubItems(2).Text, lstItem .SubItems(3).Text, lstItem .SubItems(4).Text, "MISSING", Format(Now, "dd/MM/yyyy")))
                Next
      For Each lstItem2 As ListViewItem In listview2.Items
                    csvFile.WriteLine(String.Format("{0},{1},{2},{3},{4},{5},{6},{7}", lstItem2.Text, lstItem2.SubItems(0).Text, lstItem2.SubItems(1).Text, lstItem2.SubItems(2).Text, lstItem2.SubItems(3).Text, lstItem2.SubItems(4).Text, "FOUND", Format(Now, "dd/MM/yyyy")))
                MessageBox.Show("Successful")
            End Using

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width