c# - CellEditEnding not working -
i have datagrid on want control value entered numeric.
so when enter wrong value in picture
i want restore previous value.
to need catch new entered value when that
you can see still old value before editing. have got new entered value has analyzed after enter key pressed?
use celleditingtemplate
:
<datagridtemplatecolumn> <datagridtemplatecolumn.celltemplate> <datatemplate> <textblock text="{binding age}"/> </datatemplate> </datagridtemplatecolumn.celltemplate> <datagridtemplatecolumn.celleditingtemplate> <datatemplate> <textbox lostfocus="textbox_lostfocus" background="aquamarine" text="{binding age, mode=twoway, updatesourcetrigger=propertychanged}"/> </datatemplate> </datagridtemplatecolumn.celleditingtemplate> </datagridtemplatecolumn>
and handle lostfocus
event of textbox
.
below code reject non-integer values , revert original value.
private void textbox_lostfocus(object sender, routedeventargs e) { textbox tb = (textbox)sender; int result; if (!int.tryparse(tb.text, out result)) tb.getbindingexpression(textbox.textproperty).updatetarget(); }
Comments
Post a Comment