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 03:36 PM UTC

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 06:34 PM UTC

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 07:32 PM UTC

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 04:08 PM UTC

Thanks, that worked!

Loader.
Up arrow icon