I have setup where Field is using a Converter to convert the bound value type to string. How do I handle exceptions in the Converter? If I throw the exception the application crashes.
For example, The field is bound to double and Converter is setup convert to string and vice-versa.
<igDP:Field Name="Salary" Label="Test salary" Converter="{StaticResource StringToDoubleConverter}">
I have attached the sample code to demonstrate the exception.
What I am interested to find out is
1. Is there some mechanism to handle exception and put the focus back to cell being edited?
2. Alternative to setup the Field where invalid inputs are handled more graciously.
HI,
Please let me know if you need further assistance regarding this issue.
Don't converter your numeric data to string. The XamNumericEditor will prevent bad data from getting into your bound collection.
Hi Matt,
I don't want to write code in the event handler for each possible field setup with the converter. It would be very tightly coupled. I have lots of fields and many more to come.
HI Bhavesh,
If you need numeric data entry, then don't convert the double to a string. The XamDataGrid will use the XamNumericEditor for numeric data. This editor will not allow
nonnumeric data to be entered. Another option would be to wire up the XamDataGrid' EditModeEnding event and cancel it if the data is not in the correct format.
Here is a code snippet:
private void xgrid1_EditModeEnding(object sender, Infragistics.Windows.DataPresenter.Events.EditModeEndingEventArgs e)
{
if (e.Cell.Field.Name == "Address")
{ if (e.Editor.Text.Contains("z"))
e.Cancel = true;
}
To make the example represent more closer to my scenario I have updated the sample. Now I binding the field to Custom type MyDouble.
Attached the updated sample