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

Change color of Selected row in GridDataBoundGrid

Hi How do I change the color of Selected row in GridDataBoundGrid? Thanks

4 Replies

Administrator March 22, 2005 12:59 AM UTC

If you have the GridSelectionFlags.AlphaBlend set in the grid.AllowSelection property, then you can control the selection color using the grid.AlphaBlendSelectionColor property.

DB Dimitar Binev October 21, 2005 01:33 PM UTC

But this also changes the text color and in my case that''s not what I want. Is there any other way to change the selection color? >If you have the GridSelectionFlags.AlphaBlend set in the grid.AllowSelection property, then you can control the selection color using the grid.AlphaBlendSelectionColor property.

Administrator October 21, 2005 02:13 PM UTC

Try hiding the selection color and then directly set the BackColor in PrepareViewStyleInfo. To manage the currentcell getting colored(if you want this), you can refresh in in SelectionsChanged.
this.gridDataBoundGrid1.AlphaBlendSelectionColor = Color.FromArgb(0,0,0,0);
this.gridDataBoundGrid1.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(gridDataBoundGrid1_PrepareViewStyleInfo);
this.gridDataBoundGrid1.Model.SelectionChanged += new GridSelectionChangedEventHandler(Model_SelectionChanged);



private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
	if(this.gridDataBoundGrid1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex)))
	{
		e.Style.BackColor = Color.Red;
	}
}

private void Model_SelectionChanged(object sender, GridSelectionChangedEventArgs e)
{
	if(e.Range != null)
	{
		this.gridDataBoundGrid1.RefreshRange(this.gridDataBoundGrid1.CurrentCell.RangeInfo, true);
	}
}

DB Dimitar Binev October 21, 2005 02:49 PM UTC

Thanks Clay, That''s exactly what I needed! And came at lightning speed :) Warm Regards, Dimitar
Loader.
Live Chat Icon For mobile
Up arrow icon