c# - Validating binding, depending on which button is clicked -
i searched lot, didn't find right solution.
i have textbox, datagridview, 3 buttons , bindingsource.
when click button 'change' set binding , data loaded datagridview textbox, works:
textbox.databindings.add("text", bindingsource, "name", true, datasourceupdatemode.onpropertychanged); when click button 'cancel' binding cleared:
textbox.databindings.clear(); but data still transferred datagridview. think it's because of onpropertychanged. when change onvalidation, know saved, when it's validated.
but how can validate or refuse validation? have 2 buttons, , depending on whether 'save' button or 'cancel' button clicked, should transferred datagridview or not.
and event
textbox.validating += textbox_validating; i didn't running, because function called before can click button.
how can achieve this?
you can create binding datasourceupdatemode.never , store in form level variable (field). can use writevalue method apply changes (respectively readvalue revert changes).
something this:
form:
binding namebinding; change button click:
namebinding = textbox.databindings.add("text", bindingsource, "name", true, datasourceupdatemode.never); cancel button click:
namebinding.readvalue(); textbox.databindings.clear(); namebinding = null; save button click:
namebinding.writevalue(); textbox.databindings.clear(); namebinding = null;
Comments
Post a Comment