<%@ Page language="c#" AutoEventWireup="false" %> SandGrid Documentation

SandGrid User Guide

Graphical Formatting of Data

Back to Table of Contents

Foreground Colours and Fonts

The colour of text displayed in a cell depends on the setting of the ForeColorSource property on the column. The colour can be taken from the column (the default, useful for making an entire column gray for example), the row/cell (so that each cell can specify its own colour) or the grid as a whole (where all text can be changed in one location, useful for a white-on-black grid).

When the foreground colour is taken from the column the column's ForeColor property is used to set it. When the colour is taken from the row/cell, you can use the ForeColor property of each cell if you are using GridCell instances to store your data; if you are using virtual rows, you can override the DrawVirtualCell method of your row and pass the colour of your choice to the base method.

The font used to draw text has behaviour similar to the foreground colour in that it can be taken from either the column or the row/cell. A boolean property on the column, UseCellFont, controls this. The default value is true. Again, when you are using virtual rows, your overridden DrawVirtualCell method can specify the font dynamically for each cell.

Background Colours

The most common type of background fill used is to just enable the automatic alternating row background fill. This makes it easier for the human eye to track data on the same row between columns and the colour of the alternating rows is determined by the renderer in use.

SandGrid does not have a property for specifying a specific background colour on a per-row basis. To fill the background of an entire row you should derive from GridRow and override the DrawRowBackground method. We do not provide a background colour property for rows as a performance optimization and a memory saver. An example of how you might implement a custom row with a BackColor property is below.

class GridRowWithBackcolor : GridRow
{
	private Color backColor = Color.Transparent;

	protected override void DrawRowBackground(Divelements.SandGrid.Rendering.RenderingContext context)
	{
		base.DrawRowBackground(context);

		if (backColor != Color.Transparent)
		{
			using (SolidBrush brush = new SolidBrush(backColor))
				context.Graphics.FillRectangle(brush, Bounds);
		}
	}

	public Color BackColor
	{
		get { return backColor; }
		set
		{
			backColor = value;
			RedrawNeeded();
		}
	}
}

You can specify a background colour for a cell with its BackColor property.

Next: Manipulating Data