Different number format for editing and non-editing
Hi,
I'm looking for a solution to get a number format with two digits while editing (with focus) and zero digits after leaving the cell.
For example:
I want to edit cell content to "4.67", but after leaving the cell, there sould be displayed the rounded value "5".
Thanks for your help
Regards
Harald
SIGN IN To post a reply.
6 Replies
SR
Sivakumar R
Syncfusion Team
October 31, 2016 10:02 AM UTC
Hi Harald,
Your requirement can be achieved by setting DisplayBinding for GridNumerColumn with converter as below,
XAML
|
<syncfusion:GridNumericColumn MappingName="UnitPrice" NumberDecimalDigits="2" >
<syncfusion:GridNumericColumn.DisplayBinding>
<Binding Path="UnitPrice">
<Binding.Converter>
<local:NumberRounOffConverter/>
</Binding.Converter>
</Binding>
</syncfusion:GridNumericColumn.DisplayBinding>
</syncfusion:GridNumericColumn> |
Converter Code
|
public class NumberRounOffConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return string.Empty;
return Math.Round((double)(value));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
Sample:
Thanks,
Sivakumar
HB
Harald Betzler
October 31, 2016 02:17 PM UTC
The sample doesn't work, because Syncfusion.SampleLayout.dll is missing.
HB
Harald Betzler
October 31, 2016 02:48 PM UTC
And I need to configure the columns within the AutoGeneratingColumn event.
Is there a possibility to realize the DisplayBinding via C# in the event?
SR
Sivakumar R
Syncfusion Team
October 31, 2016 03:29 PM UTC
Hi Harald,
Yes, your requirement can be achieved by handling AutoGeneratingColumn event also. Please find the sample and code snippet below,
|
this.sfgrid.AutoGeneratingColumn += Sfgrid_AutoGeneratingColumn;
private void Sfgrid_AutoGeneratingColumn(object sender, Syncfusion.UI.Xaml.Grid.AutoGeneratingColumnArgs e)
{
if(e.Column.MappingName == "UnitPrice")
{
e.Column.DisplayBinding = new Binding("UnitPrice")
{
Converter = new NumberRounOffConverter()
};
}
} |
Converter class:
|
public class NumberRounOffConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return string.Empty;
return Math.Round((double)(value));
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
Sample:
Thanks,
Sivakumar
HB
Harald Betzler
October 31, 2016 04:06 PM UTC
Hi Sivakumar,
thank you for the code snippets. It works perfectly.
Regards
Harald
JG
Jai Ganesh S
Syncfusion Team
November 1, 2016 05:05 AM UTC
Hi Harald,
Thank you for the update.
Please let us know if you need further assistance on this.
Regards,
Jai Ganesh S
SIGN IN To post a reply.
- 6 Replies
- 3 Participants
-
HB Harald Betzler
- Oct 28, 2016 03:18 PM UTC
- Nov 1, 2016 05:05 AM UTC