473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to populate a second drop down based on the content of a first


Hi,

I have two drop downs and the content of the second one must changed everytime the user changes the selection in the first one. Is any easy way of doing this?

Thanks in advance.
Alonso

Nov 20 '05 #1
3 1638
Are these bound to tables in a dataset. If so, bind one to the master and
one to a DataRelation which you need to create between the master and
dependent table.

If this is not the case that they are bound, then what criteria are you
using to fill the Combo's

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Alonso" <Al****@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com...

Hi,

I have two drop downs and the content of the second one must changed everytime the user changes the selection in the first one. Is any easy way
of doing this?
Thanks in advance.
Alonso

Nov 20 '05 #2
Hi,

Change the content of the second combobox it the first combobox
selected index changed event.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
ComboBox2.DropDownStyle = ComboBoxStyle.DropDownList

ComboBox1.Items.Add("Fruit")
ComboBox1.Items.Add("Pets")
ComboBox1.Items.Add("Cars")
ComboBox1.SelectedIndex = 0
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

ComboBox2.Items.Clear()
Select Case ComboBox1.SelectedIndex
Case 0
ComboBox2.Items.Add("Apple")
ComboBox2.Items.Add("Peach")
ComboBox2.Items.Add("Orange")
Case 1
ComboBox2.Items.Add("Dog")
ComboBox2.Items.Add("Cat")
ComboBox2.Items.Add("Parrot")
Case Else
ComboBox2.Items.Add("Pickup truck")
ComboBox2.Items.Add("SUV")
ComboBox2.Items.Add("Compact Car")
End Select
ComboBox2.SelectedIndex = 0
End Sub
Ken
--------------

"Alonso" <Al****@discussions.microsoft.com> wrote in message
news:06**********************************@microsof t.com:
Hi,

I have two drop downs and the content of the second one must changed
everytime the user changes the selection in the first one. Is any easy way
of doing this?

Thanks in advance.
Alonso


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.3.6 - Release Date: 6/25/2004
Nov 20 '05 #3
* =?Utf-8?B?QWxvbnNv?= <Al****@discussions.microsoft.com> scripsit:
I have two drop downs and the content of the second one must changed
everytime the user changes the selection in the first one. Is any easy
way of doing this?


You could store objects in the 1st combobox that provide the strings for
the 2nd dropdown in a public property:

\\\
Public Class MyItem
Private m_Text As String
Private m_SubItems() As String

Public Property Text() As String
Get
Return m_Text
End Get
Set(ByVal Value As String)
m_Text = Value
End Set
End Property

Public Property SubItems() As String()
Get
Return m_SubItems()
End Get
Set(ByVal Value() As String)
m_SubItems = Value
End Set
End Property

Public Overrides Function ToString() As String
Return m_Text
End Function
End Class
///

When selection in the 1st combobox changes, you can take the selected
item of the 1st combobox and loop through its 'SubItems' and add the
items to the 2nd combobox.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Greg Scharlemann | last post by:
I am attempting to populate a drop down menu based on the selection of a different drop down menu. However, it is not working correctly, I cannot figure out for the life of me what exactly happens...
1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
1
by: rajarameshvarma | last post by:
Hi, I have two user controls in an asp.net webpage each contains a DropDownList. Depending on the selection of the drop down in one user control i need to populate data in the other drop down...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
1
by: Flanman | last post by:
I have an ASP web form that I want to populate fields based on the first field choice. Example I have 4 fields item, price, delivery, availability. I have all these items setup in an access table....
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
1
by: boss1 | last post by:
hello everyone, I am having a problem with populating second a drop down list depending on selected value of first drop down list. I have been searching the net for the last couple of days i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.