Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

collection as combobox datasource

Posted on 2006-11-17
2
Medium Priority
?
746 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 200 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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: …
Suggested Courses

722 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