Free Visual Basic 2008 Source Code VB2008
How to Write a ListView to a CSV File








HOW TO WRITE A LISTVIEW TO A CSV FILE USING VISUAL BASIC 2008 VB2008


DESCRIPTION

This Visual Basic 2008 VB2008 code is a simple source code example of writing a complete table of data from a ListView directly to a CSV file using Visual Basic 2008.


THE VB2008 SETUP

Create a ListView and write some data to it (See 'Fill A ListView') Then create a button which will be used to write the CSV file when desired. (Any method can be used to call the write routine, this is just an example)

Add the following lines to your 'Module1' code (add the Imports as the first lines above Module1 - ie at the top!)

Imports System
Imports System.IO
Imports System.Collections

Module1:


THE FREE VISUAL BASIC 2008 SOURCE CODE

Copy and Paste this VB2008 code wherever you need it:

'.....Free Source Code from www.freevisualbasic2008sourcecode.com
Write the following Sub Routine into your Module 1 so that it can be called from anywhere else in your program.

Sub WriteListViewToCSVFile()
Dim CSVWriter As New StreamWriter("C:\Test.csv")
For i As Integer = 0 To Main.ListView1.Items.Count - 1
For j As Integer = 0 To Main.ListView1.Columns.Count - 1
CSVWriter.Write(Main.ListView1.Items(i).SubItems(j).Text)
Next
CSVWriter.WriteLine()
Next
CSVWriter.Close()
End Sub


Main Form Code

'Add a button to your form and call the new subroutine when the button is pressed.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WriteListViewToCSVFile()
End Sub




Home to FreeVisualBasic2008SourceCode.com
How to write to a CSV file
How to write to a TEXT file
How to read from a CSV file
How to read from a TEXT file
How to find a User Name
How to fill a ListView
How to write a ListView data table to a CSV file
How to call another program
How to copy and paste to the Windows Clipboard
How to concatenate (join) text
How to sort and Array


Copyright SGDesigns (c)2010

Our aim is to provide simple concise and easy to follow Free Visual Basic 2008 Source Code for the casual programmer in VB2008. We hope you find the Visual Basic 2008 code example uselful. This code shows a simple method on how to write a data table from a ListView to a csv file using Visual Basic 2008.





counter