We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Different number format for editing and non-editing

Thread ID:

Created:

Updated:

Platform:

Replies:

127147 Oct 28,2016 11:18 AM Nov 1,2016 01:05 AM WPF 6
loading
Tags: SfDataGrid
Harald Betzler
Asked On October 28, 2016 11:18 AM

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

Sivakumar R [Syncfusion]
Replied On October 31, 2016 06:02 AM

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 


Harald Betzler
Replied On October 31, 2016 10:17 AM

The sample doesn't work, because Syncfusion.SampleLayout.dll is missing.



Harald Betzler
Replied On October 31, 2016 10:48 AM

And I need to configure the columns within the AutoGeneratingColumn event.

Is there a possibility to realize the DisplayBinding via C# in the event?

Sivakumar R [Syncfusion]
Replied On October 31, 2016 11:29 AM

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 


Harald Betzler
Replied On October 31, 2016 12:06 PM

Hi Sivakumar,

thank you for the code snippets. It works perfectly.

Regards

Harald

Jai Ganesh S [Syncfusion]
Replied On November 1, 2016 01:05 AM

Hi Harald,  
 
Thank you for the update. 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Jai Ganesh S 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;