I pull data from a table in a database and assign it as a datasource to a listbox. If there is a blank item in the listbox, it shows up as something like this:
What is the best way to remove the blank in the listbox. If there is a blank, it is always in the second position. I was going to try to test to see if the second position contained blank text, but I am not sure how to do that.
I'd say the best thing to do is to remove the blank item from your datasource before you bind it to the listbox.
How you do this depends on where your data's coming from and how much control you have over it.
You could add a view to the database that only returns non-blank items; if you're using LINQ to SQL you could modify your query so that it only returns non-blank items; you could copy the items into a List and remove the blank ones yourself (I guess there aren't too many items if you're putting them in a listbox).
Hook up an event to the data bind of the list box. If the data item is empty or has an invalid string, then do not add it, else go ahead an add it.
Or loop through the data source yourself, and add only what is needed.
the problem is that will only clean one item, you need to do it the as many times as empty items you have...maybe not the best solution...but it works.