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.
Syncfusion Feedback

backcolor of a cell in GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

26185 Mar 16,2005 12:49 PM UTC Mar 16,2005 02:47 PM UTC Windows Forms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On March 16, 2005 12:49 PM UTC

I need to change the background color of a cell in a GridDataBoundGrid. I do it depending on the value of another cell in the grid. I found an example on this site that changes a cell backcolor depending on it''s own value, I tried to modify it a little to get it to change the backcolor of the cell and the preceding one in the same row. (I''m aware of the problem if I change the cells of the 1st column of the grid but that''s not important now) private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.GridPrepareViewStyleInfoEventArgs e) { if(e.Style.Text == "v") { int col = e.ColIndex; int row = e.RowIndex; e.Style.BackColor = Color.Blue; /* this one works*/ gridDataBoundGrid1[row, col-1].BackColor = Color.Red; /* this does not work*/ } } does anyone have an idea why this isn''t working as I want??? (the examples on syncfusion''s site are on: http://www.syncfusion.com/support/EvaluationCenter/viewsource.aspx?lang=csharp&id=157 and the full project can be downloaded from: http://www.syncfusion.com/support/EvaluationCenter/default.aspx?cNode=5 ) thank you

Administrator [Syncfusion]
Replied On March 16, 2005 02:47 PM UTC

In PrepareViewStyleInfo, when e.RowIndex, e.ColIndex point to teh cell you might want to color, then you should do your check at that point, and set e.Style.backColor if the check indicates it should be colored. //to make sure the whole row is refreshed as needed, in form.load, set this.grid.Model.Options.RefreshCurrentCellBehavior = GridRefreshCurrentCellBehavior.RefreshRow;
//the handler
private void gridDataBoundGrid1_PrepareViewStyleInfo(object sender, 
       GridPrepareViewStyleInfoEventArgs e)
{
	//color col 2 if col 1 is "v"
	if(e.ColIndex == 2 && e.RowIndex > 0)
	{
		string s = this.gridDataBoundGrid1[e.RowIndex, 1].Text;
		if(s == "v")
			e.Style.BackColor = Color.Red;
	}
}

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.

Warning Icon 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.Close Icon

;