We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

draw line in column

Thread ID:

Created:

Updated:

Platform:

Replies:

60163 Apr 28,2007 04:04 PM May 1,2007 12:37 PM Windows Forms 4
loading
Tags: GridControl
j g
Asked On April 28, 2007 04:04 PM

How can I draw a line down a specific column? I have columns in my grid that represents half hour time blocks and the line needs to show the real time in the appropriate block. See attachment for an example.

dayplanner.zip

haneefm [Syncfusion]
Replied On April 28, 2007 05:19 PM

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

j g
Replied On April 28, 2007 10:10 PM

The code works great, but where there are covered ranges, the line will disappear. Any idea how to overcome this issue?

haneefm [Syncfusion]
Replied On April 30, 2007 06:53 PM

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

j g
Replied On May 1, 2007 12:37 PM

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!

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;