[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!
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.
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