This sample class shows how to manage and display individual colors for certain column:
[C#]
internal class CoolNode : Node, IStyledNode
{
public class NodeColors
{
private Hashtable colors;
public Color this[Column column]
{
get
{
return colors == null || !colors.Contains(column) ? Color.Empty : (Color)colors[column];
}
set
{
if (colors == null) colors = new Hashtable();
colors[column] = value;
}
}
}
#region IStyledNode Members
public CoolNode(NodeBase parent) : base(parent){}
private static NodeColors foreColors = null;
public static NodeColors ForeColors
{
get
{
if (foreColors == null)
foreColors = new NodeColors();
return foreColors;
}
}
private static NodeColors bkColors = null;
public static NodeColors BackColors
{
get
{
if (bkColors == null)
bkColors = new NodeColors();
return bkColors;
}
}
public void OnBeginPaint(CellDrawInfo info)
{
if (info.cellSelected)
{
info.customForeColor = SystemColors.Info;
}
else
{
info.customForeColor = CoolNode.ForeColors[info.currentColumn];
info.customBackColor = CoolNode.BackColors[info.currentColumn];
}
}
public void OnEndPaint(CellDrawInfo info)
{
if (info.customForeColor != Color.Empty)
{ //clear custom info
info.customForeColor = Color.Empty;
info.customBackColor = Color.Empty;
}
}
#endregion
}
This sample shows how to retreive column for certain column via OnGetForeColor/OnGetBackColor methods (that can be overriden by inheritors ):
[C#]
internal class CoolNodeWithFeedBack : Node, IStyledNode
{
#region IStyledNode Members
public CoolNodeWithFeedBack(NodeBase parent) : base(parent){}
public void OnBeginPaint(CellDrawInfo info)
{
if (info.cellSelected)
{
info.customForeColor = SystemColors.Info;
}
else
{
info.customForeColor = OnGetForeColor(info.currentColumn);
info.customBackColor = OnGetBackColor(info.currentColumn);
}
}
public void OnEndPaint(CellDrawInfo info)
{
if (info.customForeColor != Color.Empty)
{ //clear custom info
info.customForeColor = Color.Empty;
info.customBackColor = Color.Empty;
}
}
protected virtual Color OnGetBackColor(Column col)
{
return col.Caption.StartsWith("Green") ? Color.Green : Color.Empty;
}
protected virtual Color OnGetForeColor(Column col)
{
return col.Caption.StartsWith("Red") ? Color.Red : Color.Empty;
}
#endregion
}