Solved

collection as combobox datasource

Posted on 2006-11-17
2
737 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

19 Experts available now in Live!

Get 1:1 Help Now