Giter VIP home page Giter VIP logo

farjanaparveen / how-to-show-different-currency-symbol-based-on-data-in-gridcurrencycolumn-in-wpf-datagrid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syncfusionexamples/how-to-show-different-currency-symbol-based-on-data-in-gridcurrencycolumn-in-wpf-datagrid

0.0 0.0 0.0 14 KB

How to show different currency symbol based on data in GridCurrencyColumn in WPF DataGrid(SfDataGrid)?

C# 100.00%

how-to-show-different-currency-symbol-based-on-data-in-gridcurrencycolumn-in-wpf-datagrid's Introduction

How to show different currency symbol based on data in GridCurrencyColumn in WPF DataGrid(SfDataGrid)?

About the sample

How to show different currency symbol based on data in GridCurrencyColumn in WPF DataGrid(SfDataGrid)?

By default, SfDataGrid does not provide the support show the different currency symbol based on data in GridCurrencyColumn. You can achieve this by adding converter for Currency symbol and assigned it for edit element in OnInitializeEditElement method of GridCellCurrencyRenderer.

public class CurrencyConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var val = value as Employee;
if (val == null)
return "C";
var cultureInfo = new CultureInfo("fr-FR");
if (val.EmployeeID > 1005)
return "F";                
return cultureInfo.NumberFormat.CurrencySymbol;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class GridCellCurrencyRendererExt : GridCellCurrencyRenderer
{
public override void OnInitializeDisplayElement(DataColumnBase dataColumn, TextBlock uiElement, object dataContext)
{
base.OnInitializeDisplayElement(dataColumn, uiElement, dataContext);
}
public override void OnInitializeEditElement(DataColumnBase dataColumn, CurrencyTextBox uiElement, object dataContext)
{
base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
var binding = new Binding {Converter=new CurrencyConverter() };
uiElement.SetBinding(CurrencyTextBox.CurrencySymbolProperty, binding);
}
}
public class SfDataGridBehavior : Behavior<SfDataGrid>
{
protected override void OnAttached()
{
base.OnAttached();
this.AssociatedObject.CellRenderers.Remove("Currency");
this.AssociatedObject.CellRenderers.Add("Currency", new GridCellCurrencyRendererExt());
}  
}

Requirements to run the demo

Visual Studio 2015 and above versions

how-to-show-different-currency-symbol-based-on-data-in-gridcurrencycolumn-in-wpf-datagrid's People

Contributors

farjanaparveen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.