private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Category combocategory = new Category(); combocategory = (Category)comboBox1.SelectedItem; if (combocategory.Subcategories.Count == 0) { label3.Visible = false; comboBox2.Visible = false; comboBox2.DataSource = null; comboBox2.DataSource = categoryDB.GetListComboboxSubCategory((Category)comboBox1.SelectedItem); comboBox2.DisplayMember = "NameSubcategory"; return; } label3.Visible = true; comboBox2.Visible = true; comboBox2.DataSource = null; comboBox2.DataSource = categoryDB.GetSubCategories((Category)comboBox1.SelectedItem); comboBox2.DisplayMember = "NameSubcategory"; if (code == 0) { for (int i = 0; i < comboBox2.Items.Count; i++) { SubCategory subCategorybox = (SubCategory)comboBox2.Items[i]; if (subCategorybox.NameSubcategory == advertisement.Subcategory.NameSubcategory) { comboBox2.SelectedIndex = i; i = comboBox2.Items.Count; } } } }
public Advertisement Add() { categoryDB = new CategoryDB(); countryDB = new CountryDB(); discoveredDB = new DiscoveredDB(); var catigories = categoryDB.GetListCombobox(); var countries = countryDB.GetListCombobox(); var cities = countryDB.GetListComboboxCity(countries[0]); var subcatigories = categoryDB.GetListComboboxSubCategory(catigories[0]); var discovereds = discoveredDB.GetDiscoveredBox(); Advertisement advertisement = new Advertisement { Address = "", Close = false, ContactPerson = "", Description = "", Header = "", Phone = 0, Time = DateTime.Now, Category = catigories[0], City = cities[0], Country = countries[0], Discovered = discovereds[0], Subcategory = subcatigories[0] }; advertisements.Add(advertisement); Save(); return(advertisement); }
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox3.SelectedIndex == -1) { return; } Category combocategory = new Category(); combocategory = (Category)comboBox3.SelectedItem; if (combocategory.NameCategory == "" || combocategory.Subcategories.Count == 0) { label4.Visible = false; comboBox4.Visible = false; comboBox4.DataSource = null; comboBox4.DataSource = categoryDB.GetListComboboxSubCategory(combocategory); comboBox4.DisplayMember = "NameSubcategory"; return; } label4.Visible = true; comboBox4.Visible = true; comboBox4.DataSource = null; comboBox4.DataSource = categoryDB.GetListComboboxSubCategory(combocategory); comboBox4.DisplayMember = "NameSubcategory"; }