We use a xamGrid, one of the columns is a double value which is defined with a mask:
<ig:TemplateColumn Key="TransferRate" HeaderText="Transfer Rate" Width="96" IsResizable="False" HorizontalContentAlignment="Right" HeaderTextHorizontalAlignment="Right">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding TransferRate, Mode=OneWay, StringFormat=\{0:n6\}}"/>
</DataTemplate>
</ig:TemplateColumn.ItemTemplate>
<ig:TemplateColumn.EditorTemplate>
<ig:XamNumericEditor Text="{Binding TransferRate}" Value="{Binding TransferRate, Mode=TwoWay}" Mask="{}{double:-4.6}" ValueChanged="XamNumericEditor_ValueChanged" PromptChar=" " GotFocus="XamNumericEditor_GotFocus" SelectionBackground="{StaticResource BlueSelectionBackgroundBrush}"/>
</ig:TemplateColumn.EditorTemplate>
</ig:TemplateColumn>
One of the requirements is: if the value is removed we should set the default value: 0.0 this was easily achieved using an converter or validating this in the ValueChanged event:
public class TransferRateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
if ( value == null || String.IsNullOrWhiteSpace(value.ToString().Trim()) || value.ToString().Trim().Equals(".") )
value = 0.0;
or
private void XamNumericEditor_ValueChanged(object sender, RoutedEventArgs e)
XamNumericEditor xne = sender as XamNumericEditor;
if (xne.Value == null || String.IsNullOrEmpty(xne.Text.Trim()) || xne.Text.Trim().Equals("."))
xne.Value = 0.0;
xne.Text = "0.0";
This is working fine, the problem appears when we remove the value and try to modify the same value again. Once we click into the column the text is selected and when you press any key number (let say 8) we can see this: 08.000000 and then you can type two more digits and you cannot overwrite the decimal part.
I tried to solve this manipulating the text value in the ValueChanged event doing something like:
string originalText = xne.Text != null ? xne.Text.Trim() : String.Empty;
bool intergetPart = true;
string result = String.Empty;
if (xne.Text.ToString().StartsWith("0") && !xne.Text.Equals("0.000000"))
Char[] aux = xne.Text.ToArray();
foreach (char digit in aux)
if (digit.Equals('.') && originalText.Length > 4)
intergetPart = false;
result = String.Format("{0}{1}", result, '.');
if (intergetPart)
if (!digit.Equals(0))
result += digit;
else
result = String.Format("{0}{1}", result, originalText.Substring(5, originalText.Length - 5));
break;
if(String.IsNullOrEmpty(result))
result = "0.0";
xne.Text = result;
xne.Value = Convert.ToDouble(result);
The result is again wrong, now I can see something like: 0.800000 and I can enter only one number.
Is there a way (somehow) to synchronize the text property and the value property? Or is there a way to set the text property exactly as we want (xne.Text =8 -> result 8)? Do I miss something?
Please see attached file for more information.
Hello kshetty,
When you once remove the value of a cell, it automatically accepts ‘0.000000’ and the cursor is positioned before the decimal separator. This is the reason why a zero appears in front of the value that you want to enter.I can suggest you handle the ‘CellExitingEditMode’ event of the XamGrid instead of the ‘ValueChanged’ event of the XamNumericEditor like :
private void MyGrid_CellExitingEditMode(object sender, Infragistics.Controls.Grids.ExitEditingCellEventArgs e)
XamNumericEditor xne = e.Editor as XamNumericEditor;
if (xne.Value == null)
If you have any other question on this matter, feel free to ask.
Unfortunately I found another issue. The CellExitingEditMode allows me to handle the default and everything seems to work fine. However after you set the value you want, if you select part of that value and try to overwrite that part the control behaves wrong as I reported previously.
Let say we have 966.999999 and we want 966.991111. If you click in that cell all the text is selected and, if you select manually the last 4 digits and start typing "1" you can see this: 966.1. The decimal part was removed once we press "1". The same occurs when you select the last 4 digits and press the "Delete" key, the entire decimal part is deleted instead of the 4 digits we selected.
This doesn't happen in the integer part. Following the previous example, if you have 966.999999 and we want 911.999999. If you click in the cell and then select manually the second and the third digit (from the integer part) once you press "1" you can see this: 91.999999 which is correct.
This makes me think the problem is related to the ValueChanged event of the XamNumericEditor control.
My current definition is:
<TextBlock Text="{Binding TransferRate, Mode=TwoWay, StringFormat=\{0:n6\}}"/>
<ig:XamNumericEditor Value="{Binding TransferRate, Mode=TwoWay}" Mask="{}{double:-3.6}" PromptChar=" " InsertMode="False" DisplayMode="IncludeBoth" GotFocus="XamNumericEditor_GotFocus" SelectionBackground="{StaticResource BlueSelectionBackgroundBrush}"/>
private void XamNumericEditor_GotFocus(object sender, RoutedEventArgs e)
xne.SelectAll();
private void MyGrid_CellExitingEditMode(object sender, ExitEditingCellEventArgs e)
if (e.Cell.Column.Key == "TransferRate")
I'll appreciate any help on this.
Regards.
I have logged this behavior with our developers in our tracking system, with an issue ID of 107233. I have also created a support ticket on your behalf with number CAS-87856-VS2F93 in order to link the development issue to it so that you are automatically updated when a Service Release containing your fix is available for download.