PDA

Click to See Complete Forum and Search --> : [RESOLVED] Fill a Listview with info from .txt file


robert_anisoiu
Jun 12th, 2009, 02:39 AM
Hi,

In a mobile application I need to read from a .txt file and fill with information a ListView Control. I don't know why a receive an error.

The code is below:

Dim StreamReader As IO.StreamReader
Dim line As String
StreamReader = New IO.StreamReader("Smart Card\fisier.txt")

While StreamReader.Peek <> -1
line = StreamReader.ReadLine()
ListView1.Items.Add(line)
End While

The error message is in "ListView1.Items.Add(line)"; "Error 1 Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem'.

The .txt file contain first name and given name separated by a space and I want to display the list of names in a ListView Control.

Can anybody help me?

Thank you,
Robert

petevick
Jun 12th, 2009, 09:57 AM
You need to add a listview item to a listview.After
line = StreamReader.ReadLine()
try
Dim lvItem as new listviewitem
lvitem.text = line
listview1.items.add (lvitem)

That should do it - although I haven't checked the code in Visual Studio

robert_anisoiu
Jun 15th, 2009, 06:39 AM
Thank you a lot.