3 Replies - 1988 Views - Last Post: 09 June 2012 - 05:10 PM Rate Topic: -----

#1 OmitZz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 04-May 12

Removing only empty items from a listbox

Posted 09 June 2012 - 03:09 PM

I need to know if there is a way to remove any items from a listbox if they contain no text. Like if there are three items(Blah, ,Blah) listed in the listbox like so...

Blah

Blah

(remove the middle line that is empty so the listbox now contains two items(Blah, Blah) listed like so

Blah
Blah

Or if there is a way to do this to a textbox that would work too. I'm working in VB 2010

Is This A Good Question/Topic? 0
  • +

Replies To: Removing only empty items from a listbox

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 96
  • View blog
  • Posts: 899
  • Joined: 15-October 10

Re: Removing only empty items from a listbox

Posted 09 June 2012 - 04:33 PM

you could look into, If listbox.contains "" then, and so on
Was This Post Helpful? 0
  • +
  • -

#3 OmitZz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 04-May 12

Re: Removing only empty items from a listbox

Posted 09 June 2012 - 05:08 PM

View Postm_wylie85, on 09 June 2012 - 04:33 PM, said:

you could look into, If listbox.contains "" then, and so on

Here is what I have tried with no success
Dim str As String
str = ListBox1.Items(ListBox1.Items.Count - 1)
        If str = Nothing Then
            ListBox1.Items.RemoveAt(str)
        End If


Was This Post Helpful? 0
  • +
  • -

#4 Jeff H  Icon User is offline

  • D.I.C Regular

Reputation: 112
  • View blog
  • Posts: 308
  • Joined: 30-January 11

Re: Removing only empty items from a listbox

Posted 09 June 2012 - 05:10 PM

Why not check before you add it to the listbox?


If String.IsNullOrWhiteSpace returns false then remove it.
http://msdn.microsof...whitespace.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1