Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have this current code for saving a ListBox to a file....

VB
Public Sub logfile()
Dim FILE_NAME As String = "F:\NEwFolder\FileLog.txt"

Dim cnt As Integer

Dim objwriter As New System.IO.StreamWriter(FILE_NAME, True)

Do While cnt < ListBox1.Items.Count

objwriter.WriteLine(ListBox1.Items(cnt), New Font("Time New Roman", 30), Brushes.Black, 200, 200 + (cnt * 32))

cnt = cnt + 1
Loop

objwriter.Close()

End Sub
I have swapped the listbox for a listview, How can I adapt this code to work for the listview?

Thanks for any Help :D
Posted
Updated 20-Oct-14 9:55am
v2
Comments
[no name] 20-Oct-14 14:35pm    
Did you read the documentation for the ListView?
Sergey Alexandrovich Kryukov 20-Oct-14 15:55pm    
Please indent your code properly (use "Improve question" above), to make it more readable. What is the problem?
—SA

1 solution

First of all, as Wes Aday advised in his comment to the question, just read the documentation on ListView. You did not tell us exact full name of the type, but it could be this one of these three:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.listview%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview%28v=vs.110%29.aspx[^].

In principle, it could be some other, similar but unrelated type. Can you see now how important to indicate exact type names in your questions, as well as application type?

Now, there are no cases when hard-coded file paths, such as your ""F:\NEwFolder\FileLog.txt"", could be useful. Do you understand that the drive "F:" and even "C:" might not be available (or accessible) on the target system. Moreover, the code could be run on Mono or other CLR on some OS, such use Unix-like, where there is not such thing as the concept of "drive letter". File paths should always be calculated during run-time, based on user input, some configuration files, environment, and so on.

Finally, you can do printing using the class named "PrintDocument", one or another:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument%28v=vs.110%29.aspx[^],
or http://msdn.microsoft.com/en-us/library/system.windows.printing.printdocument%28v=vs.95%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900