Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Which Listbox event in vb.net

Posted on 2016-07-17
3
28 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 63

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 63

Expert Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

840 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