Listview/ Listbox Help

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts Page 1 of 1
Contributors
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Listview/ Listbox Help
upperdrag
Ok Guys Now I need help on viewing the text file in either listbox or listview.

Either i view from a file, which i need to like separate them from the ","
or i can view from the website,

one line= one item

thanks in advance.
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Listview/ Listbox Help
mandai
Code: Select all
Dim lines As String() = File.ReadAllLines("file.txt")
For i As Integer = 0 To lines.Length - 1
      ListBox1.Items.Add(lines(i))
Next
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: Listview/ Listbox Help
upperdrag
thank you for the reply, but i was hoping to see it getting sorted out by the comma for eg

TXT FILE:

[Mary Said Hi][John Said Hi]

Listbox/Listview

[Mary Said Hi]
[John Said Hi]
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Listview/ Listbox Help
mandai
Try this:
Code: Select all
        Dim lines As String() = File.ReadAllLines("file.txt")
        For i As Integer = 0 To lines.Length - 1
            Dim subitems As String() = lines(i).Split(","c)
            For i2 As Integer = 0 To subitems.Length - 1
                ListBox1.Items.Add(subitems(i2))
            Next

        Next
Where the input looks like this:
item
item2,item3,item4
item5

The output will be:
item
item2
item3
item4
item5
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

Re: Listview/ Listbox Help
upperdrag
THank You Mandai, +rep
5 posts Page 1 of 1
Return to “Tutorial Requests”