This question is locked. New answers and comments are not allowed.
in Q2, this code worked fine, to format columnar data in $0.00 format:
Now, with Q3, the converter is only applied when the cell is in Edit mode. Worse, it throws an exception when leaving the cell, because ConvertBack() is trying to convert a string of $0.00 format to a float. It seems completely backwards from what Q2 did.
If this is not a bug, what would be the correct way to implement this?
Thanks.
EDIT: I opened a support case for this, #261228, and sent along a sample project. Thanks
| GridViewDataColumn gvdc = (GridViewDataColumn)_dg.Columns[x]; |
| if (gvdc.DataMemberBinding.Converter == null) { |
| gvdc.DataMemberBinding.Converter = new FloatToMoneyConverter(); |
| } |
| public class FloatToMoneyConverter : IValueConverter { |
| public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { |
| double val = System.Convert.ToDouble(value); |
| string fval = String.Format("{0:C}", val); |
| return fval; |
| } |
| public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture ) { |
| return System.Convert.ToDouble(value); |
| } |
| } |
Now, with Q3, the converter is only applied when the cell is in Edit mode. Worse, it throws an exception when leaving the cell, because ConvertBack() is trying to convert a string of $0.00 format to a float. It seems completely backwards from what Q2 did.
If this is not a bug, what would be the correct way to implement this?
Thanks.
EDIT: I opened a support case for this, #261228, and sent along a sample project. Thanks