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.

CellBackGround

Thread ID:

Created:

Updated:

Platform:

Replies:

29313 May 23,2005 08:59 AM May 23,2005 02:34 PM Windows Forms 3
loading
Tags: GridControl
Stefan Tsalapatis
Asked On May 23, 2005 08:59 AM

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

Administrator [Syncfusion]
Replied On May 23, 2005 09: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);
		}
	}
}

Stefan Tsalapatis
Replied On May 23, 2005 02: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);
>		}
>	}
>}
>
>

Administrator [Syncfusion]
Replied On May 23, 2005 02: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;
}

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.

;