Assembly: Dapfor.Wpf (in Dapfor.Wpf.dll) Version: 4.1.0.26317 (4.1.0.26317)
Syntax
C# |
---|
public abstract class ConverterBaseAttribute : Attribute |
Visual Basic |
---|
Public MustInherit Class ConverterBaseAttribute Inherits Attribute |
Visual C++ |
---|
public ref class ConverterBaseAttribute abstract : public Attribute |
F# |
---|
[<AbstractClassAttribute>] type ConverterBaseAttribute = class inherit Attribute end |
Remarks
A very important feature in GridControl 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 Int32, Double, Decimal etc. To show this data in grid cells, it's sufficient to convert the necessary values into the 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 GridControl provides a very powerful system of converters to transform values into strings and vice-versa. These converts 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 converter classes, where data presentation is centralized.
In programming, converters can be defined in the following places:
- As an attribute of a class property. For example: ConverterAttribute, DoubleConverterAttribute, EmptyConverterAttribute, etc.
- In a column: Column.ValueConverter = 'your converter';
This converter can be declared with the DoubleConverterAttribute. The following example demonstrates this:
Copy | |
---|---|
public class Product { private double price; //With this declaration all double values are formatted with DoubleConverter. [DoubleConverter(Precision = 3, ShortForm = true, ShowZero = false)] public double Price { get { return price; } } } //Populate the grid and set a specified converter for the 'SomeColumn' public void PopulateGrid(GridControl grid) { //Initialize the grid grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("SomeColumn")); //Another way to set up the converter grid.Headers[0]["SomeColumn"].ValueConverter = new DoubleConverter(2, false, false); //Populate the grid grid.Rows.Add(new Product()); } |
Inheritance Hierarchy
System..::..Attribute
Dapfor.Wpf.Converters..::..ConverterBaseAttribute
Dapfor.Wpf.Converters..::..ConverterAttribute
Dapfor.Wpf.Converters..::..DoubleConverterAttribute
Dapfor.Wpf.Converters..::..EmptyConverterAttribute