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?
To style the AlternateRows, the ConditionalFormattingCellControl has a second Background property called AltBackground which is applied on the AlternateRows.
For the grid try giving IsAlternateRowsEnabled="False"
Try if the style gets applied
Or you could write your own custom conditional formatting rule to handle your case:
There is a sample on this forum post that shows how to write your own rule
http://community.infragistics.com/forums/p/53040/275151.aspx#275151
zjl_jane said: 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
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
In this case you can try to use several BetweenXandYConditionalFormatRules. For example:
... <ig:XamGrid.Columns> <ig:TextColumn Key="Int"> <ig:TextColumn.ConditionalFormatCollection> <ig:BetweenXandYConditionalFormatRule LowerBound="0" UpperBound="10" IsInclusive="True" IsTerminalRule="True" StyleToApply="{StaticResource MyYellowCFR}" /> <ig:BetweenXandYConditionalFormatRule LowerBound="11" UpperBound="40" IsInclusive="True" IsTerminalRule="True" StyleToApply="{StaticResource MyRedCFR}" /> </ig:TextColumn.ConditionalFormatCollection> </ig:TextColumn> </ig:XamGrid.Columns> ...
Regards
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?