Hello.
Can somebody help me please to remove blank lines from listbox?
And remove specified text from listbox (text line that i can specify in form code(But if i specify to remove line something like "http://www.google.com/" it will remove the line "http://www.google.com/" but doesn't remove line "http://www.google.com/chrome/" etc ). Please help me somebody because i searched for hours in google, but can't find anything... Sorry for my english. I hope you understand what i want, because i'm a complete newbie with VB.

I use Microsoft Visual Studio 2008

My code for adding items to listbox is:

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim PageElements As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("img")

        For Each CurElement As HtmlElement In PageElements


            ListBox1.Items.Add(CurElement.GetAttribute("src") & Environment.NewLine)

        Next

    End Sub

Cicle over the items and determine wich one is to be removed from the list.

Just as a hint, if you cicle from last to first, removing the item will not affect to the loop.

Dim ValueToSearchFor as String = "XYZ"

For I as Integer =  ListBox1.Items.count - 1 to 0 step -1
  If ListBox1.Items(I).Tostring.Trim.Length = 0 then
    ListBox1.Items.RemoveAt(I)
  Else
    If ListBox1.Items(I).Tostring.IndexOf(ValueToSearchFor)<>-1
      ListBox1.Items.RemoveAt(I)
    End If
  End If
Next

Hope this helps

Thanks, i managed to make it work for me. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.