Gets or sets cell format.

Namespace: Dapfor.Net.Ui
Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)

Syntax

C#
public IFormat Format { get; set; }
Visual Basic
Public Property Format As IFormat
	Get
	Set
Visual C++
public:
property IFormat^ Format {
	IFormat^ get ();
	void set (IFormat^ value);
}
F#
member Format : IFormat with get, set

Property Value

Type: IFormat
The format.

Remarks

A very important feature in .Net Grid 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 ToString()()()() or Format(String, Object). 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:
     Copy imageCopy
    public class Product
    {
        private double price;
    
        [DoubleFormat(Precision = 3, ShortForm = true, ShowZero = false)]
        public double Price
        {
            get { return price; }
        }
    }
  • In a column: Column.Format = 'your format';
  • Directly in a Cell (this method requires a lot of memory): Cell.Format = 'your format';

The .Net Grid looks for IFofmat object to format values or parse strings in the following order:

  • In a Cell
  • In a Column returned by the Column property
  • In a IDataField object, returned by the DataField property.
  • If the format is still not found, the grid uses default format for the specified object type.

Some formats greatly simplify application development. For example, StringFormat, enables use of standard patterns for formatting values through Format(String, Object):

 Copy imageCopy
column.Format = new StringFormat("### ### ### ###", string.Empty, " $");
//The value 12345 will be displayed in cells as "12 345 $"

.NET Framework has similar system of type conversion based on the TypeConverter class that enables conversion of values to strings and vice versa. This conversion system is more complete, but a little bit cumbersome in the context of formating and data parsing. Althrough converters are bulky, such approach enables development of a business logic independently from data presentation. In a perfect case all these mechanisms can be completely based on Microsoft's component model and therefore have no physical dependencies on libraries of other vendors and on the Dapfor libraries as well.

 Copy imageCopy
class SomeClass
{
    private int intValue;

    [TypeConverter(typeof(HexTypeConverter))]
    int SomeHexdecimalValue
    {
        get { return intValue;  }
        set { intValue = value; }
    }
}

Thread Safety

The property is thread-safe.

See Also