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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #13549 |

    I have a column, lets say ‘grade’ which only have integer value 0-5, I want to use graphic/images/progressbar instead of numbers, and I still want the sorting works if user click on this column, is it posible and how ?

    Imported from legacy forums. Posted by narf03 (had 659 views)

    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)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.