Populate parent dropdownbox based on child dropdownbox.

I have two dropdownboxes.

One has the following possibles values:
cboLegacySystem is the first dropdownbox:
AMAPS
PIOS
PX
IMS
AMPS

Now if the user selects AMAPS or PIOS then the second dropdownbox should be enabled
with the following values:
cboLegacySubSystem is the second dropdownbox:
Finance
Engineering
Manufacturing

Otherwise disable the second dropdownbox.

This is what I have so far:

Private Sub cboLegacySystem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLegacySystem.SelectedIndexChanged
        If ((cboLegacySystem.SelectedValue = 0) Or (cboLegacySystem.SelectedValue = 1)) Then
            ' Populate cboLegacySubSystem dropdownbox
            ' Enable cboLegacySubSystem dropdownbox
            cboLegacySubSystem.Enabled = True
            ' First Value will be Finance
            ' Second Value will be Engineering
            ' Third Value will be Manufacturing
        Else
            ' Disable cboLegacySubSystem dropdownbox
            cboLegacySubSystem.Enabled = False
        End If

    End Sub

    Private Sub cboLegacySubSystem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLegacySubSystem.SelectedIndexChanged

    End Sub

How should I do this?

Note when I populated the first dropdownbox I used the items and just add the values where it says (collections)

mathieu_cuprykAsked:
Who is Participating?
 
Brian CroweConnect With a Mentor Database AdministratorCommented:
You should only populate cboLegacySubSystem dropdownbox once.  To prevent a value from being displayed after it is disabled set the selectedindex = -1


private sub myform_load(...) handles mybase.load
    ...
   'you could also choose to do this at design time
   with cbolegacysubsystem.items
      .add("Finance")
      .add("Engineering")
      .add("Manufacturing")
   end with
   ...
end sub

Private Sub cboLegacySystem_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboLegacySystem.SelectedIndexChanged
        If ((cboLegacySystem.SelectedValue = 0) Or (cboLegacySystem.SelectedValue = 1)) Then
            ' Enable cboLegacySubSystem dropdownbox
            cboLegacySubSystem.Enabled = True
            cbolegacysubsystem.selectedindex = 0
        Else
            ' Disable cboLegacySubSystem dropdownbox
            cbolegacysubsystem.selectedindex = -1
            cboLegacySubSystem.Enabled = False
        End If
    End Sub
0
 
mathieu_cuprykAuthor Commented:
Is it better to do?

with cbolegacysubsystem.items
      .add("Finance")
      .add("Engineering")
      .add("Manufacturing")
 end with

with the properties  = > Items = > Collections

and add the following manually.



0
 
mathieu_cuprykAuthor Commented:
Good job!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.