i want to add items from webbrowser to listview

i had use these codes to add in text1.text

text1.text = WebBrowser1.Document.Body.InnerText

now i want to use listview

i try this LV.ListItems = WebBrowser1.Document.Body.InnerText but its wrong
need lil Help with this code

6 Years
Discussion Span
Last Post by AndreRet

Grabbing the inner text from a web page means that you are grabbing ALL of the source code contained within it. a List view is to display certain values in different coloumns.

You need to get a value from say a textbox on webpage, bind it to a string value and then insert the value into a coloumn in the listview.

Give us the page you want to grab data from...


This is how I would go about, seeing that the page returned a list of IP Addresses..

I'll save the returned text to a text file on pc.
Open this text file and then read from it line by line.
I'll also add it to a listbox and not a listview because it has only 1 coloumn data. It is much easier to manipulate the data in a listbox than it is from a listview which is similar to a data grid.

My code will look something like this -

Dim nFileNum As Integer, sText As String, sNextLine As String, lLineCount As Long

Private Sub Command3_Click()

' Get a free file number
nFileNum = FreeFile

' Open a text file for input. inputbox returns the path to read the file
Open App.Path & "\Test.txt" For Input As nFileNum
lLineCount = 1
' Read the contents of the file
Do While Not EOF(nFileNum)
   Line Input #nFileNum, sNextLine
   'do something with it
   'add line numbers to it, in this case!
   sNextLine = sNextLine & vbCrLf
   sText = sNextLine

    List1.AddItem sText
''list1.AddItem = sText

' Close the file
Close nFileNum

End Sub

Private Sub Command1_Click()

Text1.Text = WebBrowser1.Document.Body.InnerText
End Sub

Private Sub Command2_Click()

Dim intHandle As Integer

intHandle = FreeFile

''Write data to text file...
Open App.Path & "\Test.txt" For Output As intHandle
    Print #intHandle, Text1.Text
Close intHandle
End Sub

Private Sub Form_Load()

WebBrowser1.Navigate2 ("http://warriors-rules.com/salman/Socks.txt")
End Sub

You can now manipulate the data in list box -

List1.ListIndex = 9

MsgBox List1.Text

''Will return the text on line 10 of Listbox - remember listbox index starts at 0...

bro my application is simple see these codes

Private Sub Command1_Click()
'it works
Text1.Text = WebBrowser1.Document.Body.InnerText
End Sub

Private Sub Command2_Click()
'Problem is in this line
LV.ListItems = WebBrowser1.Document.Body.InnerText
End Sub

Private Sub Form_Load()
WebBrowser1.Navigate ("http://warriors-rules.com/salman/Socks.txt")
End Sub

its just 1 line


Your problem is becuase the returned value from webbrowser is one loooong string. you need to break it down first. Again, a listview is just an extension of the listbox with the difference that you can icons etc to it. You are not adding fancy stuff, use a listbox.

If you really want to use a listview, you still need to call the data line for line. It is a LOT of code to get it from a textbox, use a listbox then add to listview from there -

Private Sub Command4_Click()

Dim xLines As Integer

For xLines = 0 To List1.ListCount - 1
    List1.ListIndex = xLines

    ListView1.ListItems.Add , , List1.Text
Next xLines
End Sub

i use ur codes it works but my all txt changes , in the end of every line extra blocks added when load in list1 from text file test.txt


Not sure what you are refering to here. I've checked and text loads fine into textbox, then to list box and then add each line to a listview.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.