When you fill the 2nd combobox then you also fill one arraylist which contains the primary key for first combobox value for eg:
comboBox1.Items.Add("1");
comboBox1.Items.Add("2");
when you fill the second combo
define a arraylist as arrfk and arrcombobox2
arrfk.Add("1");
arrcombobox2.Add("11");
arrfk.Add("1");
arrcombobox2.Add("12");
arrfk.Add("2");
arrcombobox2.Add("21");
arrfk.Add("2");
arrcombobox2.Add("22");
Now on selectedindexchanged event of first combobox call this method
private void fillcombobox2()
{
combobox2.Items.Clear();
for (int i = 0; i <= arrfk.Count = 1; i++)
{
if (arrfk[i].ToString().ToLower().Trim() == comboBox1.SelectedText.ToString().ToLower().Trim())
{
combobox2.Items.Add(arrcombobox2[i]);
}
}
It is like this :
Suppose Combobox 1 contains items such as 1,2,3.
And Combobox 2 contains items such as A,B,C,D,E,F,G,H,I.
When 1 is chosen in combobox 1 then A,B,C should be shown in combobox 2
When 2 is chosen in combobox 1 then D,E,F should be shown in combobox 2.
When 3 is chosen in combobox 1 then G,H,I. should be shown in combobox 2.
IAmateur
Member
96 Points
388 Posts
Combo box in vb
Apr 21, 2012 06:29 PM|LINK
If user clicks on one of the options of combo box then another combo box should show only paticular 3 items as options out of 6 items .
How to do this?
Time to go Long way...
tusharrs
Contributor
3230 Points
668 Posts
Re: Combo box in vb
Apr 21, 2012 08:17 PM|LINK
Hi,
When you fill the 2nd combobox then you also fill one arraylist which contains the primary key for first combobox value for eg:
comboBox1.Items.Add("1");
comboBox1.Items.Add("2");
when you fill the second combo
define a arraylist as arrfk and arrcombobox2
arrfk.Add("1");
arrcombobox2.Add("11");
arrfk.Add("1");
arrcombobox2.Add("12");
arrfk.Add("2");
arrcombobox2.Add("21");
arrfk.Add("2");
arrcombobox2.Add("22");
Now on selectedindexchanged event of first combobox call this method
private void fillcombobox2()
{
combobox2.Items.Clear();
for (int i = 0; i <= arrfk.Count = 1; i++)
{
if (arrfk[i].ToString().ToLower().Trim() == comboBox1.SelectedText.ToString().ToLower().Trim())
{
combobox2.Items.Add(arrcombobox2[i]);
}
}
}
( Mark as Answer if it helps you out )
View my Blog
IAmateur
Member
96 Points
388 Posts
Re: Combo box in vb
Apr 22, 2012 03:49 AM|LINK
It is like this :
Suppose Combobox 1 contains items such as 1,2,3.
And Combobox 2 contains items such as A,B,C,D,E,F,G,H,I.
When 1 is chosen in combobox 1 then A,B,C should be shown in combobox 2
When 2 is chosen in combobox 1 then D,E,F should be shown in combobox 2.
When 3 is chosen in combobox 1 then G,H,I. should be shown in combobox 2.
how to do this?
Time to go Long way...
tusharrs
Contributor
3230 Points
668 Posts
Re: Combo box in vb
Apr 23, 2012 04:35 AM|LINK
Hi,
comboBox1.Items.Add("1");
comboBox1.Items.Add("2");
comboBox1.Items.Add("3");
when you fill the second combo
define a arraylist as arrfk and arrcombobox2
arrfk.Add("1");
arrcombobox2.Add("A");
arrfk.Add("1");
arrcombobox2.Add("B");
arrfk.Add("1");
arrcombobox2.Add("C");
arrfk.Add("2");
arrcombobox2.Add("D");
arrfk.Add("2");
arrcombobox2.Add("E");
arrfk.Add("2");
arrcombobox2.Add("F");
arrfk.Add("3");
arrcombobox2.Add("G");
arrfk.Add("3");
arrcombobox2.Add("H");
arrfk.Add("3");
arrcombobox2.Add("I");
Now on selectedindexchanged event of first combobox call this method
private void fillcombobox2() {
combobox2.Items.Clear();
for (int i = 0; i <= arrfk.Count = 1; i++)
{
if (arrfk[i].ToString().ToLower().Trim() == comboBox1.SelectedText.ToString().ToLower().Trim())
{
combobox2.Items.Add(arrcombobox2[i]);
}
}
}
( Mark as Answer if it helps you out )
View my Blog