public Elemente(Elemente CopyFrom) { _Name = CopyFrom.Name; foreach (Element p in CopyFrom.ElementListe) { ElementListe.Add(new Element(p)); } }
private void buttonSave_Click(object sender, EventArgs e) { string newName = ""; Asker ask = new Asker(); ask.StartPosition = FormStartPosition.CenterScreen; ask.Answer = comboBoxList.Text; ask.Question = "Name für neuen Datensatz angeben"; DialogResult dr = ask.ShowDialog(); if (dr == DialogResult.OK) { if (comboBoxList.Text == ask.Answer) { DialogResult dr2 = MessageBox.Show("Die Liste mit dem Namen " + ask.Answer + " überschreiben?", "Überschreiben", MessageBoxButtons.YesNo); if (dr2 != DialogResult.Yes) return; deleteCurrent(); } newName = ask.Answer; } else { return; } if (DataSource.GetType() == typeof(BindingList<Elemente>)) { BindingList<Element> newList = new BindingList<Element>(); foreach (Element elm in (BindingList<Element>)((DataGridView) RelControl).DataSource) { newList.Add(new Element(elm)); } Elemente el = new Elemente(); el.ElementListe = newList; el.Name = newName; ((BindingList<Elemente>)DataSource).Add(el); comboBoxList.SelectedItem = el; } else if (DataSource.GetType() == typeof(BindingList<Phasen>)) { BindingList<Phase> newList = new BindingList<Phase>(); foreach (Phase elm in (BindingList<Phase>)((DataGridView)RelControl).DataSource) { newList.Add(new Phase(elm)); } Phasen el = new Phasen(); el.PhasenListe = newList; el.Name = newName; ((BindingList<Phasen>)DataSource).Add(el); comboBoxList.SelectedItem = el; } else if (DataSource.GetType() == typeof(BindingList<TextElement>)) { TextElement el = new TextElement(newName, ((TextBox)RelControl).Text); ((BindingList<TextElement>)DataSource).Add(el); comboBoxList.SelectedItem = el; } }