private void button1_Click(object sender, EventArgs e)// Save XML { try { Adress temp = new Adress(adress.State, adress.City, adress.Street, adress.House, adress.FlatNumber); flat.adress = temp; flats.Add(flat); XmlSerializer formatter = new XmlSerializer(typeof(List <Flat>)); using (FileStream fs = new FileStream("flats.xml", FileMode.OpenOrCreate)) { formatter.Serialize(fs, flats); } textBox1.Text = ""; flat = new Flat(); this.MetrComboBox.Text = MetrComboBox.Items[0].ToString(); this.flat.Year = HouseAge.Value.ToString("dd-MM-yyyy"); this.flat.CountOfRooms = (int)RoomsNumericUpDown1.Value; this.flat.Floor = (int)FLOORnumericUpDown2.Value; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void Fill(Flat flat) { DataGridViewCell floor = new DataGridViewTextBoxCell(); DataGridViewCell state = new DataGridViewTextBoxCell(); DataGridViewCell city = new DataGridViewTextBoxCell(); DataGridViewCell metrag = new DataGridViewTextBoxCell(); floor.Value = flat.Floor; state.Value = flat.adress.State; city.Value = flat.adress.City; metrag.Value = flat.Metr; DataGridViewRow row = new DataGridViewRow(); row.Cells.AddRange(floor, state, city, metrag); dataGridView1.Rows.Add(row); }