Hi everyone, I'm working on my first winforms EDM project and I'm trying to populate a Datagridview with a list of Presenters that can be updated by a user. The cols in my grid are Name and Email address(DataGridViewLinkColumn). So far I have been able to display the grid correctly but when I try to add a new row my changes are not being saved back to the DB even though I get a msgbox to say they have. Here's how I'm populating my DGV:
I'm unable to edit the Email address field as well (i think this may be a seperate thread)C# Code:
private void frmPresenters_Load(object sender, EventArgs e) { dal = new DataAccessLayer(); try { //Get the List of Contacts from the DAL and bind to the DataGrid source = new BindingSource(); source.DataSource = dal.GetPresentersList(); this.dgvPresenters.DataSource = source; dgvPresenters.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dgvPresenters.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; } catch (Exception ex) { MessageBox.Show(string.Format("Exception occurred: {0}", ex.Message)); } }
all updates are made by clicking a button:
Can anyone help me please?C# Code:
private void btnSave_Click(object sender, EventArgs e) { try { // Save object changes to the database, display a message, and refresh the form. this.source.EndEdit(); //dal.entities.SaveChanges(); MessageBox.Show("Changes saved to the database."); this.Refresh(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }




Reply With Quote