private void loadGrid() { try { Console.WriteLine("Entre"); var reader = new StreamReader(File.OpenRead(path)); string line = reader.ReadLine(); line = reader.ReadLine(); List <AllTowns> towns = new List <AllTowns>(); while (!string.IsNullOrEmpty(line)) { string[] array = line.Split(','); int idDepartment = Int32.Parse(array[0]); int idTown = Int32.Parse(array[1]); string nameDepartment = (array[2]); string nameTown = (array[3]); string type = (array[4]); AllTowns all = new AllTowns(idDepartment, idTown, nameDepartment, nameTown, type); colombia.add(idDepartment, idTown, nameDepartment, nameTown, type); //Console.WriteLine(all.ToString()); towns.Add(all); line = reader.ReadLine(); } dataGridView1.DataSource = towns; comboBox1.Visible = true; comboBox2.Visible = true; } catch (Exception wtf) { Console.WriteLine(wtf.ToString()); } }
// combo box para filtrar datos por tipo private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { //filtrar por municipio, isla, area no municipalizad int index = comboBox2.SelectedIndex; List <AllTowns> townsGrid = new List <AllTowns>(); List <Department> departments = colombia.departments; foreach (Department department in departments) { List <Town> towns = department.towns; foreach (Town town in towns) { int idDepartment = department.id; int idTown = town.id; string nameDepartment = department.name; string nameTown = town.name; string type = town.type; bool add = false; switch (index) { case 0: Console.WriteLine(type); if (type.Equals(Town.MUNICIPIO)) { add = true; } break; case 1: if (type.Equals(Town.ISLA)) { add = true; } break; case 2: if (type.Equals(Town.NO_MUNICIPALIZADA)) { add = true; } break; default: add = true; break; } if (add) { AllTowns all = new AllTowns(idDepartment, idTown, nameDepartment, nameTown, type); townsGrid.Add(all); } } } dataGridView1.DataSource = townsGrid; }