Is there a way to have the renderer of a cell render to a graphics object instead of/ or in addition to the grid.
I really tried to insert some code into the query cell info, but it called QueryCellInfo again (recursivly) in response to the CreateRenderer renderer call.
Any ideas about how to render the cell image into a Graphics object when I already have the complete GridStyle object?
AD
Administrator
Syncfusion Team
February 9, 2005 06:02 PM UTC
We use following code in our grouping grid for dragging headers with showing a image of the header cell in it:
private Bitmap CreateHeaderBitmap(int rowIndex, int colIndex)
{
Graphics g = null;
Size size = new Size(GridGroupDropArea.GetColWidth(colIndex), GridGroupDropArea.GetRowHeight(rowIndex));
Rectangle bounds = new Rectangle(Point.Empty, size);
GridStyleInfo style = GridGroupDropArea.Model[rowIndex, colIndex];
GridCellRendererBase headerCellRenderer = grid.CellRenderers[style.CellType];
Bitmap bm = new Bitmap(size.Width, size.Height);
try
{
g = Graphics.FromImage(bm);
BrushPaint.FillRectangle(g, bounds, style.Interior);
headerCellRenderer.Draw(g, bounds, rowIndex, colIndex, style);
}
finally
{
if (g != null)
g.Dispose();
}
return bm;
}
Stefan
>Is there a way to have the renderer of a cell render to a graphics object instead of/ or in addition to the grid.
>
>I really tried to insert some code into the query cell info, but it called QueryCellInfo again (recursivly) in response to the CreateRenderer renderer call.
>
>
>Any ideas about how to render the cell image into a Graphics object when I already have the complete GridStyle object?
AD
Administrator
Syncfusion Team
February 10, 2005 04:49 PM UTC
Why do i have in fact to go throught the model ?
Can i directly draw the cell ?
I feel like there is the :
Grid -- GridModel -- MyDataSorted - Mydata
Isn''t it too much ?
AD
Administrator
Syncfusion Team
February 10, 2005 11:55 PM UTC
All you need is:
1) Get the bounds, e.g. grid.RangeInfoToRectangle
2) Get the style, e.g. Model[row, col]
3) Get the renderer: grid.CellRenderers[style.CellType]
4) call renderer.Draw, e.g. headerCellRenderer.Draw(g, bounds, rowIndex, colIndex, style);
Stefan
>Why do i have in fact to go throught the model ?
>Can i directly draw the cell ?
>
>I feel like there is the :
>Grid -- GridModel -- MyDataSorted - Mydata
>
>Isn''t it too much ?
AD
Administrator
Syncfusion Team
February 11, 2005 02:42 PM UTC
I tried the code but got the following error...
at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.DrawBackground(Graphics g, Rectangle rect, GridStyleInfo style, Boolean fillBackground)
at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style)
Any idea ?
The only difference is that i created a style from scractch instead of using the model...
AD
Administrator
Syncfusion Team
February 11, 2005 04:50 PM UTC
If you create the style from scratch be sure to associate the style object with a GridStyleInfoIdentity object with correct row index and column index.
Stefan
>I tried the code but got the following error...
>
>
>at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.DrawBackground(Graphics g, Rectangle rect, GridStyleInfo style, Boolean fillBackground)
> at Syncfusion.Windows.Forms.Grid.GridCellRendererBase.Draw(Graphics g, Rectangle cellRectangle, Int32 rowIndex, Int32 colIndex, GridStyleInfo style)
>
>Any idea ?
>The only difference is that i created a style from scractch instead of using the model...
>