How to format a cell to show an empty cell based on the value of the cell

I have two cases where I'm trying to figure out how to show a blank cell:

1) value of the cell is 0 (For TreeGridNumericColumn,  TreeGridPercentColumn, TreeGridCurrencyColumn)

2) value of cell is DateTime.MinValue (For TreeGridDataTimeColumn)

For numeric type columns, I want to preserve the defined values for  CurrencyGroupSeparator, CurrencyGroupSizes,  CurrencyDecimalDigits

I define the columns for the grid using C# not xaml

Thanks


5 Replies

MA Manikanda Akash Munisamy Syncfusion Team May 13, 2024 06:16 PM UTC

Hi Bob Bachman,

'AllowNullValue' is the property used to indicate whether the null values are allowed on editor columns. You can declare those properties as a nullable variables, and you can enable 'AllowNullValue' for those columns to format an empty cell. I have attached a simple sample with one TreeGridNumericColumn which accept nullable value and shows empty cell by default.

Kindly refer the following UserGuide Documentation for DataFormatting.

Column Types in WPF TreeGrid control | Syncfusion


Regards,
Manikanda Akash


Attachment: WpfApp1_ad277a02.zip


BB Bob Bachman May 15, 2024 04:34 PM UTC

Thank you but this did not solve my problem.  The data in the object bound to the grid row is not null it contains a value of 0 or a value of minimum date value.  I want to display those fields as empty.  



SB Sweatha Bharathi Syncfusion Team May 16, 2024 03:20 PM UTC

Hi  Bob Bachman,

We have reviewed your requirement. You can display empty fields when the NumericColumn value is 0 and the TreeGridDateTimeColumn value is the Minimum DateTime value by using a converter for display binding. This converter allows you to check for the specified conditions and return null when they satisfy the condition.


We have provided a sample for your reference. Kindly review the sample and let us know if you have any further concerns on this.


Code Snippet :


 

  treeGrid.Columns.Add(new TreeGridTextColumn() { MappingName = "FirstName" });

  treeGrid.Columns.Add(new TreeGridTextColumn() { MappingName = "LastName" });

  treeGrid.Columns.Add(new TreeGridNumericColumn() { MappingName = "Salary", AllowNullValue = true, DisplayBinding = new Binding("Salary") { Converter = new EmptyConverter() } });

  treeGrid.Columns.Add(new TreeGridDateTimeColumn() { MappingName = "JoinedDate", AllowNullValue = true, DisplayBinding = new Binding("JoinedDate") { Converter = new EmptyConverter() } });

 

 

 

  public class EmptyConverter : IValueConverter

  {

 

      public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

      {

          if(value is DateTime && (DateTime)value == DateTime.MinValue)

          {

              return null;

          }

 

          if(value is 0)

          {

              return null;

          }

          return value;

      }

 

      public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

      {

          throw new NotImplementedException();

      }

  }



Attachment: SfTreeGrid_Demo4_6_2_21f1a4b3.zip


BB Bob Bachman May 18, 2024 04:38 PM UTC

Thank you - I had tried that but a consequence of that method is that the column definition for CurrencyDecimalDigits or PercentDecimalDigits or NumberDecimalDigits  as well as the value for GroupSeparator is lost.


My tree grid defines the columns from meta data that is stored in a column definition object.  Each column can have a different number of decimals that is set when the column is created.  I'm trying to find a method that allows both the number of decimals and blank if zero to be created without having to define a number of different converters.  Is that possible? 


I also tried setting the ValueBinding with the same result.



SB Sweatha Bharathi Syncfusion Team May 20, 2024 02:24 PM UTC

Hi Bob Bachman ,


We have reviewed your scenario. We support the 'AllowNullValue' property, which indicates whether null values are allowed in editor columns. You can declare those properties as nullable variables and enable 'AllowNullValue' for those columns to format an empty cell.


However, your requirement involves customizations for your application to display empty fields when the NumericColumn value is 0 and the TreeGridDateTimeColumn value is the Minimum DateTime value. To achieve this, we suggest using converters. We do not have any direct method to achieve this.


Loader.
Up arrow icon