private void btEdit_Click(object sender, EventArgs e) { if (dgUsers.SelectedRows.Count == 0) { return; } StringBuilder sb = new StringBuilder(); sb.Append(dgUsers[0, dgUsers.CurrentRow.Index].Value.ToString() + ' '); sb.Append(dgUsers[1, dgUsers.CurrentRow.Index].Value.ToString()); string[] result = sb.ToString().Split(' '); List <PhoneNumber> pn = new List <PhoneNumber>(); for (int i = 3; i < result.Length - 1; i += 2) { pn.Add(new PhoneNumber(result[i], result[i + 1])); } Contact contact = new Contact(result[0], result[1], result[2], pn); contact.id = (dgUsers.CurrentRow.Index + 1).ToString(); FormForEdit form = new FormForEdit(user, contact); form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { user = form.list; } for (int i = 0; i < form.list.contacts.Count; i++) { dgUsers.Rows.Add(); dgUsers.Rows[i].Cells[0].Value = form.list.contacts[i].surname + " " + form.list.contacts[i].name + " " + form.list.contacts[i].patronymic; StringBuilder s = new StringBuilder(); foreach (PhoneNumber number in users[index].contacts[i].numbers) { s.Append(number.ToString() + " "); } dgUsers.Rows[i].Cells[1].Value = s; } }
private void btEdit_Click(object sender, EventArgs e) { if (dgUsers.SelectedRows.Count == 0) { return; } StringBuilder sb = new StringBuilder(); sb.Append(dgUsers[0, dgUsers.CurrentRow.Index].Value.ToString() + ' '); sb.Append(dgUsers[1, dgUsers.CurrentRow.Index].Value.ToString()); string[] result = sb.ToString().Split(' '); List<PhoneNumber> pn = new List<PhoneNumber>(); for (int i = 3; i < result.Length-1; i+=2) { pn.Add(new PhoneNumber(result[i], result[i+1])); } Contact contact = new Contact(result[0], result[1], result[2], pn); contact.id = (dgUsers.CurrentRow.Index + 1).ToString(); FormForEdit form = new FormForEdit(user, contact); form.ShowDialog(); if (form.DialogResult == DialogResult.OK) { user = form.list; } for (int i = 0; i < form.list.contacts.Count; i++) { dgUsers.Rows.Add(); dgUsers.Rows[i].Cells[0].Value = form.list.contacts[i].surname + " " + form.list.contacts[i].name + " " + form.list.contacts[i].patronymic; StringBuilder s = new StringBuilder(); foreach (PhoneNumber number in users[index].contacts[i].numbers) { s.Append(number.ToString() + " "); } dgUsers.Rows[i].Cells[1].Value = s; } }