By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

How Do I Write ListView items to a text file?

P: 6

I'm having trouble writing the contents of a ListView Control, one line at a time, to a text file.

I am able to write the lines of a ListBox Control to a text file using the code below, but the same will not work for a ListView control even if there are no subitems.

In my application I must use the ListView control because I must have several columns.

Can anyone help me with this?

Expand|Select|Wrap|Line Numbers
  2. Public Class Form1
  4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6.         Dim objFile As New System.IO.StreamWriter("C:\Test.txt")
  7.         Dim intcounter As Long = ListBox1.Items.Count
  8.         For intcounter = 0 To ListBox1.Items.Count - 1
  9.             objFile.WriteLine(Listbox1.Items(intcounter).ToString)
  10.         Next intcounter
  11.         objFile.Close()
  12.     End Sub
  13. End Class
Jan 5 '13 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,382
With listview controls, you can use the GetItemAt(x,y) method to get the data from a certain row and column.
Jan 7 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.