Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)
Syntax
C# |
---|
public class EmptyFormat : IFormat |
Visual Basic |
---|
Public Class EmptyFormat Implements IFormat |
Visual C++ |
---|
public ref class EmptyFormat : IFormat |
F# |
---|
type EmptyFormat = class interface IFormat end |
Remarks
A very important feature in .Net Grid is its ability to work directly with application business logic. Business logic is a set of classes that may have certain properties returning specific values, i.g. prices, quantities, dates, etc. Generally these values are represented by primitive types, such as System.Int32, System.Double, System.Decimal etc. To show this data in grid cells, it's sufficient to convert the necessary values into the System.String type by calling Object.ToString() or String.Format("{0}", value). However, this approach is not flexible and doesn't support parsing strings to objects. To fill in for this, the .Net Grid provides a very powerful system of formats to convert values into strings and vice-versa. These formats are fully customizable. For instance, the grid can display empty strings instead of "0" when a value equals 0 or add a separator between thousands or some prefix or suffix like "$". These formats can also parse strings back into values. For application programming it's better to have a set of format classes, where data presentation is centralized.
In programming, formats can be defined in the following places:
- As an attribute of a class property. For example: FormatAttribute, DoubleFormatAttribute, EmptyFormatAttribute, etc.
- In a column: Column.Format = 'your format';
- Directly in a cell (this method requires a lot of memory): Cell.Format = 'your format';
This format can be declared with the EmptyFormatAttribute. The following example demonstrates this:
Copy | |
---|---|
//Some data object public class Product1 { private double price; //There is no displayed text in cells. [EmptyFormat] public double Price { get { return price; } } } //Other data object public class Product2 { private double price; public double Price { get { return price; } } } //Populate the grid with data objects public void PopulateGrid(Grid grid) { //Initialize grid grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("Price")); //Populate grid. Only the Product2 price will displayed grid.Rows.Add(new Product1()); grid.Rows.Add(new Product2()); } |