Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

VB .Net VS 2005 List Box Multiple Select

Hi, I am trying to do what should be a simple thing with a list box with mutliple selected values and can not seem to get anywhere near what I want as the result.

Basically I have a mutli select list box with 10 categories which are "cat 1" through to "cat 10".

What I would like to do is check which items in the list box are selected and then have them added to a csv string. So, the output for selected items 1, 3 and 5 would be "cat1, Cat3, Cat5".

I have played with this for hours now and just do not seem to ba able to make progress.

Have checked and tried many of the posting already listed but none seem to work.
  • 4
  • 2
1 Solution
What about the following (not tested)

Dim sCSV As String = ""
For Each cat As Object In listBox1.SelectedItems
    sCSV &= cat.ToString()
    sCSV &= ","
sCSV = sCSV.Trim(New Char() {","C})

Open in new window

Tested, seems to work for me... :). Let me know if you have trouble implementing it for yourself.
OlympicNigelAuthor Commented:
Abel, Thats great.

The next question is how does it work with a databound set of items?

All I get back is:

"Systen.Data.DataRowView, Systen.Data.DataRowView"
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

> The next question is how does it work with a databound set of items?

please, stick to one question at the time. See here: http://www.experts-exchange.com/help.jsp?hi=23 if you need some assistance.

Unless it is related and you can't get the solution to work without it. But then I don't understand your question, I'm afraid. Where are you on? Can you show the code you have got so far? Is this ASP.NET or VB.NET forms?

OlympicNigelAuthor Commented:

Apologies for the wrong use of the site. I am new and had not made myself fully aware of the rules etc.

Apologies and thank you for pointing out my error.

No worries. Sometimes it is not as clear cut, but we are trying to keep it simple, as experts, so that we know that when we start answering to a question, that we also know it ends when the question is resolved. But sometimes (or just as often), the asker needs just a bit more guidance to get it working, or forgot to mention some details about his situation.

Tx for the points, and glad that this bit is sorted ;-). On to the next!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now