TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Peter Dzuya
NA
313
40.7k
Refreshing main form
Oct 14 2016 7:37 AM
Hi All,
I have two forms, one holding a list of all contacts named "frmContactsListing". The contact is selected from grid.
The other is named "frmEditContact", manages the edit of a single selected contact from "frmContactsListing".
The code from "frmContactsListing" looks as shown below:-
private void barButtonEditContact_ItemClick(object sender, ItemClickEventArgs e)
{
try{
var selectedContact = gridViewContacts.GetFocusedRow() as Contact;
frmEditContact editContact = new frmEditContact(selectedContact, _contactService);
editContact.ShowDialog();
}
catch (Exception Errhandler){
MessageBox.Show(Errhandler.Message);
}
}
And the code from "frmEditContact" looks as shown below:-
public frmEditContact(IContactService contactService) {
InitializeComponent();
_photoService = UnityConfig.GetContainer().Resolve<IContactPhotoService>();
_contactService = contactService;
}
public frmEditContact(Contact contact, IContactService contactService)
: this(contactService) {
this._contact = contact;
SelectedPhotoId = _contact.ContactId;
contactNameTextEdit.Text = _contact.ContactName;
physicalAddressTextEdit.Text = _contact.PhysicalAddress;
postalAddressTextEdit.Text = _contact.PostalAddress;
telephoneTextEdit.Text = _contact.Telephone;
photoBindingSource.DataSource = _photoService.GetById(_contact.ContactId);
byte[] byteImg = ImageToByteArray(contactPhotoPictureBox.Image);
}
private void simpleButtonAccept_Click(object sender, EventArgs e) {
try {
_contact.ContactName = contactNameTextEdit.Text;
_contact.PhysicalAddress = physicalAddressTextEdit.Text;
_contact.PostalAddress = postalAddressTextEdit.Text;
_contact.Telephone = telephoneTextEdit.Text;
contactBindingSource.EndEdit();
_contactService.Update(_contact);
byte[] byteImg = ImageToByteArray(contactPhotoPictureBox.Image);
var photoSelection = _photoService.GetById(SelectedPhotoId);
photoSelection.PhotoData = byteImg;
photoBindingSource.EndEdit();
_photoService.update(photoSelection);
} catch(Exception Errhandler) {
MessageBox.Show(Errhandler.Message);
}
}
public byte[] ImageToByteArray(Image img) {
System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
return ms.ToArray();
}
The simpleButtonAccept_Click method accepts the edit.
Now, How do I refresh "frmContactsListing" once the edit form is closed to accomodate the edit changes,
taking into cosideration I have updated two binding sources, contactBindingSource and photoBindingSource. Entity framework.
Thanks.
Peter Dzuya.
Reply
Answers (
2
)
How to remove style attribute from html string in asp.net?
Show progress bar until HttpClient response not come