This project is read-only.

How to override DrawCell method from SourceGrid.Cells.Views.Cell

Jun 28, 2011 at 2:47 PM


i'm fairly new in C# coding and that might be the reason why i can't solve the problem but i have to ask
because otherwise i can't make a step forward.

My problem is that i want to manipulate content from a cell and furthermore i want to add something.
That depends on the cellcontent. After having a look in APIReference.chm i saw

public void DrawCell(
	CellContext cellContext,
	GraphicsCache graphics,
	RectangleF rectangle

an that is exactly what i need.

The documentation says the best way to change the cell look is deriving a class from cell:

public class MyView : SourceGrid.Cells.Views.Cell
        protected override void DrawCell_Background(SourceGrid.Cells.ICellVirtual p_Cell,
         SourceGrid.Position p_CellPosition, PaintEventArgs e, Rectangle p_ClientRectangle)
                base.DrawCell_Background (p_Cell, p_CellPosition, e, p_ClientRectangle);

                e.Graphics.DrawEllipse(Pens.Red, p_ClientRectangle);

In this class i see after typing protected override among other things
OnDraw, OnDrawBackground and OnDrawContent but they have no cellcontext in it.

How can i archieve to override DrawCell? Any tips?

After reading some threads somebody suggest to
"try overriding IView.DrawCell"
Can you give me an example? i have no idea how to do this.

Many thanks in advance for your help

Jul 1, 2011 at 3:05 PM

Hi Kutte,

What i usually do is download source code (which is at and browse through the code.  CHM file you are referring is completely out of date.



Looking at class ViewBase:211     method DrawCell first calls PrepareView with cell context, and afterwards galls method Draw.

So you can easily override PrepareView and do whatever you want


Jul 2, 2011 at 11:26 AM

Hello dariusdamalakas,

thank you very much for your tip with the sourcecode.
Overriding PrepareView is exactly what i need.


Greets Kutte

Jan 14, 2012 at 5:55 AM

Is there a way to change all cell default height programaticly. I mean for my app there is quite lot space wasted between Cell borders and text.

I want to make cell border as tight as possible (perhaps with few pixels offset) from hosted text/data in it.