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. Image for the cookie policy date

Cell Spacing

Is there a concept of cell spacing within the Syncfusion Grid? By cell spacing, I mean that the grid renders space between the cells. I would lile this because I have a situation where cells in the grid have different back colors and no text. I would like to display space between these cells so that there is some space between the colors. If there is no cell spacing attribute, is there another way to get around this issue?

1 Reply

AD Administrator Syncfusion Team May 5, 2005 05:50 PM UTC

One way you can do this is to handle the DrawCellBackground event and draw the background there yourself. In order for this event to be hit on a particular cell, you must set that cell''s style.Interior = Syncfusion.Drawing.BrushInfo.Empty;. So, for example, you could have code like this:
//in form.load set the styles empty on these cells.
this.gridControl1[2,2].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[2,3].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[2,4].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[3,2].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[3,3].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[3,4].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[4,2].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[4,3].Interior = Syncfusion.Drawing.BrushInfo.Empty;
this.gridControl1[4,4].Interior = Syncfusion.Drawing.BrushInfo.Empty;

//the handler
private void gridControl1_DrawCellBackground(object sender, GridDrawCellBackgroundEventArgs e)
	Rectangle rect = e.TargetBounds;
	int off = 3;
	rect = new Rectangle(rect.X + off, rect.Y + off, rect.Width - 2 * off, rect.Height - 2 * off);
	Color c = (e.Style.Interior.IsEmpty) ? Color.Red : e.Style.BackColor;
	using (Brush b = new SolidBrush(c))
		e.Graphics.FillRectangle(b, rect);
	e.Cancel = true;

Live Chat Icon For mobile
Up arrow icon