private void addButton_Click(object sender, EventArgs e) { //make new contacts object and add it to bindingSource Contact newContact = new Contact(); ContactDetailsForm dirForm = new ContactDetailsForm(); // META data binding source - modify newContact without the // need to pass it directly ;) dirForm.DataBindingSource.DataSource = newContact; dirForm.canDelete = false; dirForm.ShowDialog(); //show model contact details form if (dirForm.closeAccept == true) { DataBindingSource.Add(newContact); RefreshItems(); //since new contact added, refresh the items in grid view } }
private void addFromCutCopy_Click(object sender, EventArgs e) { using (Stream stream = new FileStream(defaultPath, FileMode.Open, FileAccess.Read)) { IFormatter formatter = new BinaryFormatter(); Contact x = (Contact)formatter.Deserialize(stream); ContactDetailsForm dirForm = new ContactDetailsForm(); dirForm.DataBindingSource.DataSource = x; dirForm.canDelete = false; dirForm.ShowDialog(); if (dirForm.closeAccept == true) { DataBindingSource.Add(x); RefreshItems(); } } }
private void contactDataGrid_DragDrop(object sender, DragEventArgs e) { string sourceText = (string)e.Data.GetData(typeof(string)); string[] terms = sourceText.Split('\n'); //make new contacts object and add it to bindingSource Contact newContact = new Contact(); newContact.FirstName = (terms.Length >= 1) ? terms[0].Split(' ')[0] : newContact.FirstName; newContact.LastName = (terms.Length >= 1) ? (terms[0].Split(' ').Length > 1)? terms[0].Split(' ')[1] : newContact.LastName : newContact.LastName; newContact.CellPhone = (terms.Length >= 2) ? terms[1] : newContact.CellPhone; newContact.HomePhone = (terms.Length >= 3) ? terms[2] : newContact.HomePhone; newContact.Address1 = (terms.Length >= 4)? terms[3]: newContact.Address1; newContact.City = (terms.Length >= 5) ? terms[4] : newContact.City; newContact.State = (terms.Length >= 6) ? terms[5] : newContact.State; newContact.Zip = (terms.Length >= 7) ? terms[6] : newContact.Zip; newContact.Country = (terms.Length >= 8) ? terms[7] : newContact.Country; ContactDetailsForm dirForm = new ContactDetailsForm(); // META data binding source - modify newContact without the // need to pass it directly ;) dirForm.DataBindingSource.DataSource = newContact; dirForm.canDelete = false; dirForm.ShowDialog(); //show model contact details form if (dirForm.closeAccept == true) { DataBindingSource.Add(newContact); RefreshItems(); //since new contact added, refresh the items in grid view } }