sfDataGrid - how to hide value or show empty cell when zero


I'm working on a WPF app that shows ledger transactions and our model  has a credit amount and a debit amount property which means that one or the other column will always be zero (but never both). When showing these columns in the grid (using GridNumericColumn) I want to hide the value of the column that is zero, e.g:

Debit          Credit
======     =====
 123.45   
                  456.77

If this is possible can you please let me know how to achieve this?  I tried various formatting options but nothing seemed to work.

If it can't be hidden or set to empty could we at least display a dash ('-') as it would appear in Excel if the cell has an Accounting format?

Many thanks in advance.

Mike

1 Reply 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team November 2, 2020 09:26 AM UTC

Hi Mike C,

 
Thank you for contacting Syncfusion support.

 
You can achieve your requirement by adding converter like below,

 
<Window.Resources> 
    <local:ValueConverter x:Key ="cellValueConverter" /> 
</Window.Resources>
<
syncfusion:SfDataGrid x:Name=”dataGrid”  ItemsSource=”{Binding Orders}” AutoGenerateColumns=”False” > 
    <syncfusion:SfDataGrid.Columns> 
        <syncfusion:GridTextColumn MappingName=”OrderID”   DisplayBinding=”{Binding Path=OrderID, 
                    Converter={StaticResource cellValueConverter},Mode=TwoWay}”/> 
        <syncfusion:GridTextColumn MappingName=”CustomerID”/> 
        <syncfusion:GridTextColumn MappingName=”Country”/> 
        <syncfusion:GridTextColumn MappingName=”CustomerName”/> 
        <syncfusion:GridTextColumn MappingName=”ShipCity”/> 
    </syncfusion:SfDataGrid.Columns> 
</syncfusion:SfDataGrid> 


 
public class ValueConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        int input = (int)value; 
        if (input == 0) 
            return null; 
        return value; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        throw new NotImplementedException(); 
    } 
} 

We have prepared a sample for the same,

 


We hope it helps, please let us know if you need further assistance.

 
Regards,
Dhanasekar Mohanraj. 


Marked as answer
Loader.
Up arrow icon