SandGrid User Guide

Controlling Data

Back to Table of Contents

Controlling Data

Once your data is being shown in the grid there are a number of things the user can do to it, including editing and exporting it. All these operations along with display mean the conversion of data.

Formatting

This is the process the actual value in a cell goes through before it arrives at its destination. A value will always be formatted before it gets to the screen or other destination.

The ValueFormatting event of the SandGrid control is fired first in the formatting process. This event will give you the row and column intersection, the value itself and the desired destination type. You can then modify the value if required to assist SandGrid in the transformation. In most cases the destination type is String - for display on screen and exporting. Sometimes an editor will request a different type, though. For example, the SandGridDateTimeEditor requests a DateTime value.

After the event has been fired SandGrid checks the type of value it has, and if its type is the same as the destination type formatting ends there. If some conversion needs to happen, though, the column's FormatValue method is called and it's up to the column to perform any formatting. This includes converting a null value to whatever null representation is in effect (usually ""). The default GridColumn class simply calls the ToString method of the value.

Parsing

This is the opposite process to formatting, and is used much less. A formatted value obtained from an editor needs to be parsed back into its native form.

The ValueParsing event of the SandGrid control is again called first, with the formatted value straight from the editor. This gives the host application a chance to transform the value to the required destination type, which will be the datatype the column holds.

After the event has been fired the type is checked, and if it has already been converted the process stops. Otherwise, the ParseValue method of the column is called. In the case of the GridIntegerColumn, for example, the method will call int.Parse if it is passed a string. A null value will be passed straight through.

Exporting

Tabular data can be displayed with so many methods it is useful to have a means of exporting it from controls such as SandGrid. We have included an HTML export utility that turns a grid into an unformatted <table> element, which correctly recurses on nested grids. This is exposed with the static ExportToHtml method of the DataUtilities class.

Clipboard

Standard clipboard copy operations are supported and built-in to SandGrid. No matter the extent of your selection the grid will transform it into tab-delimited fields and place them on the clipboard, where applications like Excel can interpret them when it comes to pasting them into another grid.

You can programmatically copy the selection to the clipboard with the CopySelectedCellsToClipboard and CopySelectedRowsToClipboard methods of your grid.

Next: Rendering