Solved

collection as combobox datasource

Posted on 2006-11-17
2
741 Views
Last Modified: 2008-02-01
I'm a VB.NET novice and am having difficulty retrieving collection data.

I have a combobox using a collection as the datasource:

Dim PrinterCollection As New Collection

Me.ComboBox1.DataSource = PrinterCollection
Me.ComboBox1.SelectedIndex = 0

On SelectIndexChanged I would like to display the contents of the collection depending on what is selected in ComboBox1, but I'm not sure how to access the collection data:

Public Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged        
        'Me.Label1.Text = PrinterCollection(Me.ComboBox1.SelectedIndex) -- does not work
End Sub

Also, should I declare the variable PrinterCollection in a module to set it as a global variable? The variable scope differences between VB6 and VB.NET have me a bit confused.
0
Comment
Question by:jaw0807
2 Comments
 
LVL 6

Accepted Solution

by:
riyazthad earned 50 total points
ID: 17968853
What you are giong take  from collection. Object or Key?

You can use Me.ComboBox1.SelectedValue if you want items name.

You need to use Me.Label1.Text = PrinterCollection(Me.ComboBox1.SelectedIndex+1)

becos collection 1 based , combo seleted index 0 based.
0
 

Author Comment

by:jaw0807
ID: 17969068
Thank you. I didn't realize Collection is 1-based.
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

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 …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 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