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

CellBackGround

Hi, In an overriden DrawCell : How to draw the cell interior when is in the CurrentRow ? I want to highlight the CurrentRow but from DrawCell or another overriden event. I do not want to use the PrepareViewStyleInfo. Thanks Stefan

3 Replies

AD Administrator Syncfusion Team May 23, 2005 08:14 AM

You can try using the CellDrawn event to over-paint the selection color. (You may only need the e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex checks.)
private void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex
		&& this.gridControl1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex))
		&& !cc.IsEditing)
	{
		using(SolidBrush br = new SolidBrush(this.gridControl1.AlphaBlendSelectionColor))
		{
			e.Graphics.FillRectangle(br, e.Bounds);
		}
	}
}


ST Stefan Tsalapatis May 23, 2005 01:09 PM

Thanks Clay, It works also from the DrawCell if I have TransparentBackground and OptimizeDrawBackground = true. This is exactly the behavior I want. But I have two minor problems 1.Because of TransparentBackground=true the Grid.BackgroundColor is Empty and if I set the BackColor then from inside the TransparentBackground becomes false. ( so it redraws the cells background after what I have drawed on DrawCell ) How to draw the Grid.BackgroundColor manually ? I tried Model.Properties.BackColor but does nothing. 2. I draw also the headers and I have not problem except that when I press the row header then it redraws internally the row with the default AlphaBlend. I have set behavior as RefreshRow and ListBoxSelectionMode.None What to do to avoid the internally redrawing when I click on a row header ? Thanks again Stefan >You can try using the CellDrawn event to over-paint the selection color. (You may only need the e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex checks.) > >
>private void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
>{
>	GridCurrentCell cc = this.gridControl1.CurrentCell;
>	if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex
>		&& this.gridControl1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex))
>		&& !cc.IsEditing)
>	{
>		using(SolidBrush br = new SolidBrush(this.gridControl1.AlphaBlendSelectionColor))
>		{
>			e.Graphics.FillRectangle(br, e.Bounds);
>		}
>	}
>}
>
>


AD Administrator Syncfusion Team May 23, 2005 01:34 PM

>> so it redraws the cells background after what I have drawed on DrawCell Are you drawing the selection before you call the baseclass? If so, try switching the order of drawing the selection color and the base class call. 2. The problem may be that bu default, when you click a row header, the current cell is moved ot column 1, an dthis is where you color is being drawn. Try code like this to see if it handles this problem.
private int originalCol = -1;
private void gridDataBoundGrid1_CurrentCellMoving(object sender, GridCurrentCellMovingEventArgs e)
{
	originalCol = this.gridDataBoundGrid1.CurrentCell.MoveToColIndex;
}
private void gridDataBoundGrid1_CurrentCellActivating(object sender, GridCurrentCellActivatingEventArgs e)
{
	if(originalCol == 0)
			e.ColIndex = 0;
}

Loader.
Live Chat Icon For mobile
Up arrow icon