Solved

Which Listbox event in vb.net

Posted on 2016-07-17
3
17 Views
Last Modified: 2016-07-17
I have a listbox which has multiple selection enabled, I have a combo box on the form and I would like that to be populated by those selected in the listbox.

so if I select the first item in the listbox the combo gets updated to include that item, when another item is selected then the combo gets that row added.

Not sure which event to use

I have this code:

 For Each Item In ListCW.SelectedItems
                    If Not String.IsNullOrWhiteSpace(Item) Then
CBCWSelectedItems.additem Item.ToString()
                    Else
                        'do nothing whitespace
                    End If
                Next

Open in new window

0
Comment
Question by:PeterBaileyUk
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
Hi Peter;

If the items in the ListBox are of type String then the following code should do what you need. If they are complex objects then the code will need to be modified.
Private Sub ListBox1_SelectedValueChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedValueChanged

    ComboBox1.Items.Clear()
    Dim items = ListBox1.SelectedItems.OfType(Of String).ToArray()
    ComboBox1.Items.AddRange(items)

End Sub

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
Comment Utility
That did exactly what it needed to do thank you Fernando.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Peter, glad to help.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now