// Button Select Contact private void Button_Select_Contact_Click(object sender, EventArgs e) { // Show a From to select the Contact we watn to edit Select_Contact_Form selectContactForm = new Select_Contact_Form(); int contactId; using (selectContactForm) { selectContactForm.ShowDialog(this); contactId = Convert.ToInt32(selectContactForm.DataGridViewContactsList.CurrentRow.Cells["ContactId"].Value.ToString()); } this.textBoxContactId.Text = contactId.ToString(); }
// Button Select Contact private void Button_Select_Contact_Click(object sender, EventArgs e) { // Show a From to select the Contact we watn to edit Select_Contact_Form selectContactForm = new Select_Contact_Form(); int contactId; // Dispay the Data using (selectContactForm) { selectContactForm.ShowDialog(); contactId = Convert.ToInt32(selectContactForm.DataGridViewContactsList.CurrentRow.Cells["ContactId"].Value.ToString()); } Contact contact = new Contact(); DataTable table = contact.GetContactById(contactId); this.textBoxContactID.Text = table.Rows[0]["ContactId"].ToString(); this.textBoxFirstName.Text = table.Rows[0]["FirstName"].ToString(); this.textBoxLastName.Text = table.Rows[0]["LastName"].ToString(); // Populate the ComboBox with groups names if (table.Rows[0]["GroupId"].ToString() != string.Empty) { GetGroupsInComboBox(); this.comboBoxGroup.SelectedValue = table.Rows[0]["GroupId"]; } else { this.CheckBoxEnableGroups.Checked = false; this.comboBoxGroup.DataSource = null; this.comboBoxGroup.Enabled = false; } this.textBoxPhone.Text = table.Rows[0]["Phone"].ToString(); this.textBoxEmail.Text = table.Rows[0]["Email"].ToString(); this.textBoxAddress.Text = table.Rows[0]["Address"].ToString(); byte[] pic = (byte[])table.Rows[0]["Picture"]; MemoryStream picture = new MemoryStream(pic); this.pictureBoxContactImage.Image = Image.FromStream(picture); }