Home Forums WinForms controls Xceed Grid for WinForms Graphic/image in cell Reply To: Graphic/image in cell

User (Old forums)
Member
Post count: 23064

You could make your own CellViewer for this: make a class that implements the ICellViewer interface, then you can assign an instance of this class to the CellViewer property of the column.
Example CellViewer class:<code>public class GradeCellViewer : ICellViewer
{
int maximumGrade;
public GradeCellViewer(int maxGrade) { maximumGrade = maxGrade; }

public int GetFittedHeight(Cell cell, AutoHeightMode mode) { return -1; }
public int GetFittedWidth(Cell cell) { return -1; }

public bool PaintCellValue(GridPaintEventArgs e, Cell cell)
{
int value = (int)cell.Value;
float totalWidth = (float)e.DisplayRectangle.Width;
float valueWidth = totalWidth * value / maximumGrade;
RectangleF valueRectangle = (RectangleF)e.DisplayRectangle;
valueRectangle.Width = valueWidth;
using(Brush brush = new SolidBrush(cell.GetForeColorToPaint())
e.Graphics.FillRectangle(brush, valueRectangle);
return true;
}
}</code>Example code that uses it:<code>GradeCellViewer viewer = new GradeCellViewer(5);
myGrid.Columns[“grade”].CellViewer = viewer;</code>

Imported from legacy forums. Posted by Tommy (had 2765 views)