Link to home
Start Free TrialLog in
Avatar of jaw0807
jaw0807Flag for United States of America

asked on

collection as combobox datasource

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.
ASKER CERTIFIED SOLUTION
Avatar of riyazthad
riyazthad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jaw0807

ASKER

Thank you. I didn't realize Collection is 1-based.