• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 657
  • Last Modified:

Declare Combobox Collection????

How can I declare a "collection" for a combobox?  

Example:
     Dim JobsCollection As String = Handwork,Routing,Engineering,CADCAM

Only reason I ask, if because I have two comboboxes on my Windows App form.  I will need to fill combobox2 based on the value of what combobox1 is
0
chrisryhal
Asked:
chrisryhal
  • 4
  • 2
2 Solutions
 
chrisryhalAuthor Commented:
Oh, I forgot to mention.

Allong with that, here is what I am trying to achieve:

If ComboBox1.SelectedItem = "Jobs" Then
      ComboBox2.Collection = STRING
0
 
RonaldBiemansCommented:
What do you mean by collection because you can just do this

 Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        ComboBox2.Items.Add(ComboBox1.SelectedItem)
    End Sub
0
 
RonaldBiemansCommented:
the above code will add the item you have selected in combobox1 to combobox2
or if you only want to add after the user pressed on ok button, then just put that code in the button click event
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
chrisryhalAuthor Commented:
Here is what I am trying to achieve more in detail.

If user chooses "Part" in Combo1 then Combo2 fills with:
        Raw Material
        Dies
        IT Equipment
        Machining Equipment

If user chooses "Customer" in Combo1 then Combo2 fills with:
        Stanley
        Black and Decker
        J&L Tooling
        Snap-On

And so on
0
 
Koala119Commented:
To set a collection of values, you could use arraylist and then set the datasource of the Combo2 to the arraylist.
something like that:

        Dim al as Arraylist = New ArrayList
        al.Add("Raw Material")
        al.Add("Dies")
        al.Add("IT Equipment")

        Combo2 .DataSource = al

A reference that may help:
http://forums.aspfree.com/archive/t-26409/Data-binding-to-a-combo-box-in-NET-or-array-management-with-Combo-box
0
 
RonaldBiemansCommented:
These strings you want to put in combobox2 where do they come from ?
0
 
RonaldBiemansCommented:
if you don't have them In a table but you want to add them in code try something like this

Dim al1 As New ArrayList
    Dim al2 As New ArrayList

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
 System.EventArgs) Handles MyBase.Load
        al1.Add("Raw Material")
        al1.Add("Dies")
        al1.Add("IT(Equipment)")
        al1.Add("Machining(Equipment)")

        al2.Add("Stanley")
        al2.Add("Black and Decker")
        al2.Add("J&L Tooling")
        al2.Add("Snap-On")

    End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 1 Then
            ComboBox2.DataSource = al1
        ElseIf ComboBox1.SelectedIndex = 2 Then
            ComboBox2.DataSource = al2
        End If
    End Sub
0

Featured Post

Industry Leaders: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now