Solved

Which Listbox event in vb.net

Posted on 2016-07-17
3
26 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
ID: 41715795
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
ID: 41715800
That did exactly what it needed to do thank you Fernando.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 41715801
Not a problem Peter, glad to help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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