Well, i ll try to give you a quick example in Windows Forms.
Like you said, you got 2 combo boxes Category and Brand, i named cmbParent and cmbChild.
I declared some variables:
List<String> listParent = new List<String>();
List<Tuple<String, String>> listChild = new List<Tuple<String,String>>();
On Form_Load, i did some manual lists:
public ComboForm()
{
InitializeComponent();
listParent.Add("Sports");
listParent.Add("Countries");
listParent.Add("Continents");
listChild.Add(new Tuple<String, String>("Sports", "Handball"));
listChild.Add(new Tuple<String, String>("Sports", "Golf"));
listChild.Add(new Tuple<String, String>("Sports", "Skimboarding"));
listChild.Add(new Tuple<String, String>("Countries", "Portugal"));
listChild.Add(new Tuple<String, String>("Countries", "Mozambique"));
listChild.Add(new Tuple<String, String>("Countries", "Mexico"));
listChild.Add(new Tuple<String, String>("Continents", "Asia"));
listChild.Add(new Tuple<String, String>("Continents", "Oceania"));
foreach (var item in listParent)
{
cmbParent.Items.Add(item);
}
}
And added an event on the cmbParent, when you change the selected item, it will change the cmbChild.
private void cmbParent_SelectedIndexChanged(object sender, EventArgs e)
{
String i = cmbParent.Text;
cmbChild.Items.Clear(); //clear the child combo items.
foreach (var item in listChild)
{
if (item.Item1.Equals(i))
{
cmbChild.Items.Add(item.Item2);
}
}
}
I hope this helps, and give you an hint.
17
solved Using combo box in c# [closed]