Solved

collection as combobox datasource

Posted on 2006-11-17
2
743 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

631 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