Hi,
I want to change Cells's background to different color.
but I find that when I set the style for Cells, these cells in the alternate row cannot change color as follow chart:
The second cell should be blue, the forth cell should be yellow. But these are also default color.
I change the style in the CellControlAttached event as follow:
private void m_UserManagementGrid_CellControlAttached(object sender, CellControlAttachedEventArgs e) { if (e.Cell.Column.Key == "AccountName" && e.Cell.Value != null) { if (e.Cell.Value.ToString() == "User1" || e.Cell.Value.ToString() == "User2") { Style style = this.Resources["LastMatchStyle"] as Style;//Set Blue Color e.Cell.Style = style; } else { Style style = this.Resources["FirstMatchStyle"] as Style;//Set Yellow Color e.Cell.Style = style; } } }
Could you tell me why the setting cannot work in the alternate row ?
And is there any better method to achieve this function?
You can try the ConditionalFormatting feature of the XamGrid - you can read more about it here - http://help.infragistics.com/NetAdvantage/Silverlight/2010.3/CLR4.0/?page=xamGrid_Conditional_Formatting.html
Also, check this thread - http://community.infragistics.com/forums/p/41733/231650.aspx#231650 - to see how to set a style that changes the background of the alternate row.
Hope this helps
Thanks, the method could change the background of the alternate row.
But I find the Types of Rules in the ConditionalFormatCollection cannot statisfy my demand.
I want to set different color correspond with the cell's value.
I find the rule support 3 colors as ThreeColorScaleConditionalFormatRule.
But if I want to more than 3 colors, how to do using rule?
For xample: 0-10 set Yellow color; 11- 40 set Red; 41- 60 set Blue; 61- 70 set Black;
71- 90 set White ; 91- 100 set Brown