wpfdatagrid - I am using datagrid, whose itemsource is datatable. Can datatable primary key exceptions can be handled and displayed inside datagrid? -
my grid's item source datatable has 1 field id (primary key). have bound field datagrid template column @ runtime when pass duplicate or null value id inside datagrid column, no exception caught , datagridtextbox doesn't show error. code given below;
<usercontrol.resources> <style x:key="errorstyle" targettype="{x:type textbox}"> <setter property="padding" value="-2"/> <style.triggers> <trigger property="validation.haserror" value="true"> <setter property="background" value="red"/> <setter property="tooltip" value="{binding relativesource={relativesource self}, path=(validation.errors)[0].errorcontent}"/> </trigger> </style.triggers> </style> </usercontrol.resources> <datagrid autogeneratecolumns="false" name="userdatagrid" verticalalignment="top" width="381" itemssource="{binding datatableproperty, mode=twoway, notifyontargetupdated=true, notifyonvalidationerror=true}" issynchronizedwithcurrentitem="true" > <datagrid.columns> <datagridtextcolumn header="username" editingelementstyle= "{staticresource errorstyle}"> <datagridtextcolumn.binding> <binding path="id" validatesonexceptions="true" validatesondataerrors="true" notifyonvalidationerror="true" mode="twoway" updatesourcetrigger="propertychanged" > <binding.validationrules> <exceptionvalidationrule validationstep="updatedvalue"></exceptionvalidationrule> </binding.validationrules> </binding> </datagridtextcolumn.binding> </datagridtextcolumn> </datagrid.columns> </datagrid>
can please me, doing wrong ?
you need validate manually. check wpf datagrid practical examples: validation bound datasets.
Comments
Post a Comment