Hi,
I'm using a XamDataGrid. One of its columns is a bound integer field. Whenever I edit the value and type a non-integer value (e.g. 'test') there would be a validation error stating that "Value 'test' could not be converted." I would like to translate this message into a different language when the user changes culture. I believe I have to use an Infragistics resource customizer to accomplish this, but I cannot find this specific resource. I have been trying to find it via the following link:
http://help.infragistics.com/Help/NetAdvantage/WPF/2011.2/CLR4.0/html/WPF_Customize_Assembly_Resource_Strings.html
I have been searching for "Value '{0}' could not be converted." but cannot seem to find it in any of the links on that page. Where is it located?
I'm using netAdvantage v11.2
Regards, Stefan
Hello Stefan,
Thank you for your post. I have been looking into and I can suggest you use the approach from the link you shared with the following value:
LMSG_EnteredNumberInvalid
Like this:
Infragistics.Windows.Editors.Resources.Customizer.SetCustomizedString("LMSG_EnteredNumberInvalid", "My Value {0} is not valid");
Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
This is not the right translation string. By default, LMSG_EnteredNumberInvalid returns [Value '{0}' is not a valid number. Please enter a valid number.]
I also tried the string LMSG_ValueConstraint_CannotConvert but this is also not the correct one; this one returns [Value could not be converted to {0}]
I'm looking for a value that returns [Value '{0}' could not be converted.] but I cannot find it. I don't think it is in Infragistics.Windows.Editors.Resources
Could you please send me an isolated sample where the message is available, because I cannot be completely sure what is your scenario? I tried to enter a string into a n integer Field and I get the "Value '{0}' is not a valid number. Please enter a valid number." message.
Hi Stefan,
See my attached sample. If you run it, and change one of the values to 'XX' for example, you will see the tooltip.
I have been looking into your sample and I believe that a similar question is already discussed here:
http://ko.infragistics.com/community/forums/p/76698/389100.aspx
Krasimir has attached a sample where he changed the default tooltip, when an error occurs in some of the cells.
Hope this helps you.
My sample did not show this, but in my real application the databound object already implements the IDataErrorInfo interface. The problem is that this interface cannot help me in this case. This is because the property of the data object is of type double. When a user enters some text, this value cannot be converted to a double, so the setter for this property is never reached. Therefore, I also cannot set any error properties. It seems the error message comes from some converter or something that lies between the textbox and the databound property.
One possible solution would be to create a separate string-type property for every double-type property, then bind the grid column to the string-type property instead and then synchronize values between these 2 properties. But that would require a huge amount of code (I have 200+ classes that would need this) and it certainly doesn't seem like a nice solution to the problem. The easiest solution would be to simply reset the resource string that I mentioned before. Maybe another alternative is to insert my own converter between the textbox and databound property if that would be possible. Any thoughts?
I have modified the sample you have sent, so now the Tooltip is changed. Basically I copied the DataTemplate that is used when an error occurs and changed the Tooltip there. Please let me know if this helps you or you need further assistance on this matter.
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Setting the DataType to Double prevents users from entering incorrect characters, but it is also limited to the current UI culture only. When the culture is switched online, the control still displays the same number separator character (e.g. a dot in English). But I understand that this is a WPF problem and so it is not related to Infragistics. So, I'll continue my search on my own. Maybe I can still go with the converter approach here, I'll try it out.
Thanks for your help!
I modified the sample, so now the user is not able to enter string values. I set the UnboundField DataType Property to Double, so now only numbers can be entered. Also I can say that the tooltip for the conversion comes from the .NET. If you still want to be able to enter characters you can use a converter to set the Tooltip for all kind of errors that may occur in the Field.
Oh, and here is that code I tried:
The tooltip in the DataTemplate:
<ToolTip>
<ToolTip.Content>
<MultiBinding Converter="{StaticResource TooltipTextConverter2}">
<Binding Path="Host" />
<Binding Path="Host.DataError" />
<Binding Path="Host.Editor.Value" />
</MultiBinding>
</ToolTip.Content>
</ToolTip>
The XAML is changed into:
public class TooltipTextConverter2 : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values[0] == DependencyProperty.UnsetValue || values[1] == DependencyProperty.UnsetValue || values[1] == null) return DependencyProperty.UnsetValue; CellValuePresenter cellValuePresenter = values[0] as CellValuePresenter; string error = values[1].ToString(); object editorValue = cellValuePresenter.Editor.Value; string editorValueType = editorValue.GetType().ToString(); string errorMessageToTranslate = string.Format("Value '{0}' could not be converted.", cellValuePresenter.Value); if ((cellValuePresenter).DataError.ToString().Equals(errorMessageToTranslate, StringComparison.InvariantCultureIgnoreCase)) { return "My custom text" + cellValuePresenter.Value.ToString(); } return cellValuePresenter.DataError; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Very close, but still not 100% correct. The right message is displayed in both cases separately, but not when one error follows the other. In order to reproduce this follow these steps:
The other way around also goes wrong.
Obviously, the binding is not refreshed after the value in the textbox changes. Therefore, I already tried to replace the converter with a multivalueconverter and then add a binding to the actual textbox editor value and the dataerror as well (so you have 3 bindings in total; Host, Host.DataError and Host.Editor.Value). This fixes the first scenario (first 'abc', then -50), but not the other way around. This is because the old error message is still cached in the DataError property. It seems the IDataErrorInfo message 'overrules' the converter error message. Any thoughts?