Reputation: 1154
i'm writing a program in c# winforms and there is a TextBox
that is bound to an entity framework object:
BindingList<Settings> bindingList = BillContext.Settings.Local.ToBindingList();
field6TextBox.DataBindings.Add("Text", bindingList, "CustomerField6");
i've created a save button to save the changes into database:
private void saveCustomerFields_Click(object sender, EventArgs e){
BillContext.SaveChanges();
}
everything works fine if i click on the save button, but if i use the key shortcuts that i've created for the save button:
private void field6TextBox_KeyDown(object sender, KeyEventArgs e){
if(e.KeyData.Equals(Keys.Enter))
saveCustomerFields_Click(sender, e);
}
and
private void MainForm_KeyDown(object sender, KeyEventArgs e){
if(e.KeyData == (Keys.Control | Keys.S)){
saveCustomerFields_Click(sender, e);
}
}
although the save click event handler is called, but the BillContext.Settings.Local
doesn't change and it results in the changes not being saved into the database.
how does clicking and in code invocation of the button click event handle have different consequences(considering i don't use the method inputs)? and how can i make my key shortcuts work?
Upvotes: 0
Views: 32
Reputation: 422
Try replace
saveCustomerFields_Click(sender, e);
with
saveCustomerFields.PerformClick();
Upvotes: 1