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 Highlighting

When highlighting a range of cells with the mouse, the first cell does not have the highlighted blue color. How can I add this first cell to have the highlighted color? It appears as though the highlighted range has a "hole." I understand that Excel does not highlight the first cell either, but I want to be different. :-) Thanks for your help, Steve

4 Replies

AD Administrator Syncfusion Team April 13, 2004 11:36 AM

Yon can handle the CellDrawn event and color it there. Below is a snippet. private void gridDataBoundGrid1_CellDrawn(object sender, GridDrawCellEventArgs e) { GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex) { using(SolidBrush br = new SolidBrush(this.gridDataBoundGrid1.AlphaBlendSelectionColor)) { e.Graphics.FillRectangle(br, e.Bounds); } } }


ST Steve April 13, 2004 02:34 PM

Thanks Clay, but this code always highlights the current cell, I only want to highlight the current cell when multiple cells are selected via the mouse or shift arrows. Thanks.


AD Administrator Syncfusion Team April 13, 2004 03:32 PM

Try this code.
private void model_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
	if(e.Range.Width > 1 || e.Range.Height > 1)
	{
		GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
		this.gridDataBoundGrid1.RefreshRange(cc.RangeInfo, true);
	}
}
private void gridDataBoundGrid1_CellDrawn(object sender, GridDrawCellEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex
		&& this.gridDataBoundGrid1.Selections.Ranges.AnyRangeContains(cc.RangeInfo))
	{
		using(SolidBrush br = new SolidBrush(this.gridDataBoundGrid1.AlphaBlendSelectionColor))
		{
			e.Graphics.FillRectangle(br, e.Bounds);
		}
	}
}


ST Steve April 15, 2004 12:08 PM

Thanks, that worked!

Loader.
Live Chat Icon For mobile
Up arrow icon