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

Current Cell BackColor

Is there some way to make the current active cell have the same appearance as an inactive cell? Our grid is setting some rows to blue by calling the following code in the PrepareViewStyleInfo event handler:

e.Style.BackColor = Color.LightBlue

If we do this the active cell does not get the color change for current row but the rest of the row is fine (See row 3, column 4 in the attached screenshot). If I deactivate the cell in PrepareViewStyleInfo the cell has the correct back ground. The problem with this is that I need to keep the current cell active for navigation purposes.

ActiveCellIssue.zip

6 Replies

HA haneefm Syncfusion Team June 25, 2007 11:45 PM UTC

Hi Burke,

The Highlight Current Row Browser sample shows you how to highlight the current row. It avoids the problems that arise as you traverse the various grid states as the old current cell deactivates and the new current cell becomes active. It uses a PrepareViewStyleInfo event handler to actually modify the style of any cell that is in the current row, in order to display a highlighted cell. It uses the CurrentCellDeactivated and the CurrentCellActivated events to force the redraw of the old current row and the new current row so that only the proper row is ultimately highlighted. There are also other event handlers that are shown for other points in the flow sequence that occurs during a current cell move. Please try the broswer sample that are shipped with the Product.

Here is a path for browser sample.
C:\Program Files\Syncfusion\Essential Studio\4.4.0.49\Windows\Grid.Windows\Samples\DynamicFormatting\HighlightCurrentRow\cs

Best regards,
Haneef

Attached Browser Sample : HighlightCurrentRow.zip


BH Burke Harris June 26, 2007 03:50 PM UTC

Hello Haneef,

Thanks for the quick reply. The example you pointed while nice to have is not directly applicable to me situation. I should have pointed out that we are using the AlphaBlendSelectionColor which combines with the Cells backcolor in the inactive cells. and we would like to be able to have the current active cell have that back color.

1. Is there a way to programatically combine the backcolor and the AlphaBlendSelectionColor?

2. Is there some technique to make the active cell inactive (for appearance) but still behave like the active cell with respect to navigating.?

Thanks,
Burke

ActiveCellIssue0.zip


HA haneefm Syncfusion Team June 26, 2007 11:42 PM UTC

Hi Burke,

The problem is that the active cell is really a WindowsForms.RichTextBox and this control does not support alpha-blending. (Neither does the WindowsForms.TextBox.) if you use


[c#]
e.Style.BackColor = Color.LightBlue;

then you would see the active cell accept the backcolor. But it cannot accept the alpha-blended color. Below is a code snippet to resolve the problem.

this.gridControl1.ActivateCurrentCellBehavior = GridCellActivateAction.None;
this.gridControl1.CellDrawn += new GridDrawCellEventHandler(gridControl1_CellDrawn);


void gridControl1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex)
{
using (SolidBrush brush = new SolidBrush(this.gridControl1.AlphaBlendSelectionColor))
e.Graphics.FillRectangle(brush, e.Bounds);
}
}

Best regards,
Haneef


BH Burke Harris June 29, 2007 05:50 PM UTC

Hello Haneef,

Thanks for your help. I just wanted to follow up with my final solution. I ended up doing something very similar to what you suggested although I needed to use a DrawCell event handler instead of CellDrawn. The code below allows the following:

1. Allow color set in PrepareViewStyleInfo for all non active or static cells

2. Over paints the any color set in PrepareViewStyleInfo with the AlphaBlendSelectionColor for a static current cell.

3. Applies the this.TableStyle.BackColor for the current active (non-static) cell.

Note: I had to both Over paint and set the backcolor to get a non-static current cell to have the desired BackColor. If you have an answer for this or a better solution I would be interested to hear it.

private void QDataBoundGrid_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.RowIndex == CurrentCell.RowIndex
&& e.ColIndex == CurrentCell.ColIndex
&& e.Style.BackColor.Name != "Window"
&& e.Style.BackColor != this.AlphaBlendSelectionColor
)
{
//Ensure read only cells are overpainted with the AlphaBlendSelectionColor.
if (e.Style.CellType == "Static")
{
e.Graphics.FillRectangle(new SolidBrush(this.AlphaBlendSelectionColor), e.Bounds);
}
else if ( CurrentCell.HasCurrentCell)
{
//These two statements seem redundant but is neccesary to get the BackColor to override any color
//being set in the Instance's PrepareViewStyleInfo
//There was a problem getting a white backgorund when arrowing from cell to cell(because it does not beginedit())
e.Graphics.FillRectangle(new SolidBrush(System.Drawing.SystemColors.Window), e.Bounds);
e.Style.BackColor = System.Drawing.SystemColors.Window;
}

}
}


JS Jeba S Syncfusion Team July 2, 2007 07:09 AM UTC

Hi Burke,

When drawing the selection, the grid draws a rectangle using the alphblendcolor over the existng cells. This means the existing color
bleeds through because of the blending.

If you do not want this, you can do the following. Set the Color.A for the alphablendcolor to be zero. This will mean that the selection will not show at all. Then in PrepareViewStyleInfo, set the backcolor of any selected cell. Here is a forum thread link that discusses this and has code snippets.

http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=13587

Kindly let us know if you need any more information.

Best Regards,
Jeba.



JS Jeba S Syncfusion Team July 2, 2007 07:11 AM UTC

Hi Burke,

When drawing the selection, the grid draws a rectangle using the alphblendcolor over the existng cells. This means the existing color
bleeds through because of the blending.

If you do not want this, you can do the following. Set the Color.A for the alphablendcolor to be zero. This will mean that the selection will not show at all. Then in PrepareViewStyleInfo, set the backcolor of any selected cell. Here is a forum thread link that discusses this and has code snippets.

http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=13587

Kindly let us know if you need any more information.

Best Regards,
Jeba.


Loader.
Live Chat Icon For mobile
Up arrow icon