How to display positive and negative infinity values as strings in WPF DataGrid (SfDataGrid)?
WPF DataGrid (SfDataGrid) allows you to display the Positive infinity or Negative infinity symbol in the column by just adding the double.PositiveInfinity or double.NegativeInfinity value of business objects. For this you must use only the GridTextColumn to load infinity symbols. In edit mode, you can also skip other than numeric values for the column using SfDataGrid.CurrentCellValidating event.
C#
public ViewModel() { this.Model = records(); } private ObservableCollection<Model> records() { customer = new ObservableCollection<Model>(); customer.Add(new Model() { customername = "Alice", customerId = "AFRT", Country = "Beverton", salary = double.NegativeInfinity }); customer.Add(new Model() { customername = "Lawrence", customerId = "EDRT", Country = "Oregon", salary = 56784 }); customer.Add(new Model() { customername = "Bleso", customerId = "PIYG", Country = "Chicago", salary = double.PositiveInfinity }); customer.Add(new Model() { customername = "Abdul", customerId = "AWER", Country = "Oregon", salary = 75577 }); }
Validating event:
this.datagrid.CurrentCellValidating += Datagrid_CurrentCellValidating; ... private void Datagrid_CurrentCellValidating(object sender, CurrentCellValidatingEventArgs args) { if (args.Column.MappingName != "salary") return; double d; if(args.NewValue == null || !double.TryParse(args.NewValue.ToString(), out d)) { args.ErrorMessage = "Enter valid double value"; args.IsValid = false; } }
XAML
<Syncfusion:SfDataGrid Name="datagrid" ItemsSource="{Binding model}"> <Syncfusion:SfDataGrid.Columns> <Syncfusion:GridTextColumn HeaderText="CustomerName" MappingName="customername" /> <Syncfusion:GridTextColumn HeaderText="CustomerId" MappingName="customerId" /> <Syncfusion:GridTextColumn HeaderText="Country" MappingName="Country" /> <Syncfusion:GridTextColumn HeaderText="Salary" MappingName="salary" /> </Syncfusion:SfDataGrid.Columns> </Syncfusion:SfDataGrid>
It is not possible to use other type of columns like GridNumericColumn, GridCurrenctColumn, GridPercentageColumn.
I hope you enjoyed learning about how to display positive and negative infinity values as strings in WPF DataGrid (SfDataGrid).
You can refer to our WPF Grid feature tour page to know about its other groundbreaking feature representations. You can also explore our WPF Grid documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!