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

Highlight a row

I want to highlight rows in a gridControl. When I click on a button I set the backcolor property of the selected row to the color selected on the button. Everything was working fine but I added a background image to the grid and the backcolor can''t be used anymore. What can I do? I''m using vb.net.

3 Replies

AD Administrator Syncfusion Team July 12, 2004 01:15 PM UTC

What happens if you add the row to the grid''s Selections collection: grid.Selections.Add(GridRangeInfo.Row(someRowIndex)) Normally, this would tell the grid to draw an alphablended selection rectangle over the row, and would not affect the background image.


CM Christian Martel July 12, 2004 01:28 PM UTC

Sorry, I weren''t clear enough. This is not what I wanted to do. I have three different status for the lines of the grid : Normal(no change to backcolor),Overtime(backcolor blue), Overtime payed(backcolor orange). Each status has a button and when the user clicks on it the selected line''s backcolor changes. The problem here is that I added two background images on parts of the grid and I want to be able to apply those colors even on the background images. Thank you.


AD Administrator Syncfusion Team July 12, 2004 02:42 PM UTC

You could handle the DrawCell event, and do all the drawing yourself. This would mean filling the background and drawing the text. If you only have TextBox cells, then this would not be a lot of work as you can use the GridStaticCellRenderer.DrawText method to manage the drawing of the text for you. But if you have several different CellTypes, then this may become cumbersome. Another solution not exactly what you have now, but maybe close enough, woul dbe to handle teh CellDrawn. There is e.RowIndex points to one of your special colored cells, you could just fill a rectangle over the cell will a mostly transparent color using alphablending. This would work not matter what the cell type was. Here is a sample handler to give you the idea.
private void gridControl1_CellDrawn(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
	if(e.RowIndex == 2 && e.ColIndex > 0)
	{
		using(Brush br = new SolidBrush(Color.FromArgb(60, Color.Orange)))
		{
			e.Graphics.FillRectangle(br, e.Bounds);
		}
	} 
	else if(e.RowIndex == 5 && e.ColIndex > 0)
	{
		using(Brush br = new SolidBrush(Color.FromArgb(60, Color.Blue)))
		{
			e.Graphics.FillRectangle(br, e.Bounds);
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon