Drawing Rectangle in a Grid Cell


Hi Haneef ... i want to draw a rectangle of specified color before text in a grid cell .. how can i do this ??

Regards,
Ubaid Tariq

1 Reply

AD Administrator Syncfusion Team January 5, 2007 10:08 AM UTC

Hi Ubaid,

You can handle the DrawCell event to draw the rectangel before the cell text in a grid cell. Please try the attached sample and let me know if this helps.

Sample : DrawRectangleCell.zip

//Code....
private void gridControl1_DrawCell(object sender, GridDrawCellEventArgs e)
{
if(e.RowIndex > 0 && e.ColIndex > 0)
{
if( e.Style.Text != null && e.Style.Text != string.Empty )
{
e.Style.TextMargins.Left = 5;
e.Renderer.Draw(e.Graphics,e.Bounds,e.RowIndex,e.ColIndex,e.Style);
e.Graphics.FillRectangle(Brushes.Red,new Rectangle(e.Bounds.X,e.Bounds.Y,5,17));
e.Cancel = true;
}
}
}

Best Regards,
Haneef

Loader.
Up arrow icon