HA
haneefm
Syncfusion Team
April 28, 2007 09:19 PM UTC
Hi,
The DrawCell event is generally used to add some ornament to a standard cell, or to allow you to draw every thing. It is not intended to be used to dynamically change stype properties as these will later be reset unless you Cancel the drawing. Here is a code snippet that show you "How to draw the line in a grid cell?".
this.gridControl1.DrawCell += new Syncfusion.Windows.Forms.Grid.GridDrawCellEventHandler(gridControl1_DrawCell);
void gridControl1_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
if (e.ColIndex == 2)
{
e.Cancel = true;
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Point p1= new Point(e.Bounds.Left+ e.Bounds.Width/2,e.Bounds.Top );
Point p2 = new Point(e.Bounds.Left + e.Bounds.Width / 2, e.Bounds.Bottom);
Pen pen = new Pen(Color.Red);
pen.Width = 2;
e.Graphics.DrawLine(pen,p1,p2);
}
}
Best regards,
Haneef
JG
j g
April 29, 2007 02:10 AM UTC
The code works great, but where there are covered ranges, the line will disappear. Any idea how to overcome this issue?
HA
haneefm
Syncfusion Team
April 30, 2007 10:53 PM UTC
Hi j,
Please try this code.
void gridControl1_DrawCell(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
GridControl grid = sender as GridControl;
GridRangeInfo range;
grid.Model.CoveredRanges.Find(e.RowIndex,e.ColIndex, out range);
if( range != null
&& range!= GridRangeInfo.Empty
&& range.IntersectsWith(GridRangeInfo.Cell(e.RowIndex,2) ))
{
e.Cancel = true;
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Point p1= new Point(e.Bounds.Left+ e.Bounds.Width/2,e.Bounds.Top );
Point p2 = new Point(e.Bounds.Left + e.Bounds.Width / 2, e.Bounds.Bottom);
Pen pen = new Pen(Color.Red);
pen.Width = 2;
e.Graphics.DrawLine(pen,p1,p2);
}
else if( e.ColIndex == 2)
{
e.Cancel = true;
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Point p1= new Point(e.Bounds.Left+ e.Bounds.Width/2,e.Bounds.Top );
Point p2 = new Point(e.Bounds.Left + e.Bounds.Width / 2, e.Bounds.Bottom);
Pen pen = new Pen(Color.Red);
pen.Width = 2;
e.Graphics.DrawLine(pen,p1,p2);
}
}
Best regar
JG
j g
May 1, 2007 04:37 PM UTC
It seems to be drawing in covered ranges now, but at the wrong offset. No problem, that's something that I can work that out myself. Thanks again!