Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)
Syntax
C# |
---|
public class StringFormat : IFormat |
Visual Basic |
---|
Public Class StringFormat Implements IFormat |
Visual C++ |
---|
public ref class StringFormat : IFormat |
F# |
---|
type StringFormat = 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';
Some formats greatly simplify application development. For example, StringFormat enables use of standard patterns for formatting values through String.Format():
Copy | |
---|---|
column.Format = new StringFormat("### ### ### ###", string.Empty, " $"); The value 12345 is displayed as "12 345 $" |
The following example demonstrates how to declare StringFormat via FormatAttribute:
Copy | |
---|---|
public class Product { private DateTime maturity; [Format("yyyy-MM-dd")] public DateTime Maturity { get { return maturity; } } } |