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.

Current Cell BackColor

Thread ID:

Created:

Updated:

Platform:

Replies:

62936 Jun 25,2007 07:31 PM Jul 2,2007 03:11 AM Windows Forms 6
loading
Tags: GridControl
Burke Harris
Asked On June 25, 2007 07:31 PM

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

haneefm [Syncfusion]
Replied On June 25, 2007 07:45 PM

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

Burke Harris
Replied On June 26, 2007 11:50 AM

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

haneefm [Syncfusion]
Replied On June 26, 2007 07:42 PM

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

Burke Harris
Replied On June 29, 2007 01:50 PM

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;
}

}
}

Jeba S [Syncfusion]
Replied On July 2, 2007 03:09 AM

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.


Jeba S [Syncfusion]
Replied On July 2, 2007 03:11 AM

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.


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.

;