Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
585
How to change cell propety based on the data loaded?
posted

with xamGrid, I want to change cell font color based on the data from datasource. For example, one column named status with following kind of value:

1. Good

2. Bad

3. Not sure

then I want to all Bad status dispalyed as red font, and Good status displayed as green font.

How to implement this either in xaml or in code?

Parents
  • 6912
    Suggested Answer
    posted

    Hi,

    You can try the ConditionalFormatting feature of the XamGrid. This documentation article will geive you more information about this feature - http://help.infragistics.com/NetAdvantage/Silverlight/2010.3/CLR4.0/?page=xamGrid_Conditional_Formatting.html;

    For the case that you describe, given that the dataType of the column is string, you can use the following snippet:

    <ig:XamGrid>
        <ig:XamGrid.ConditionalFormattingSettings>
            <ig:ConditionalFormattingSettings AllowConditionalFormatting="True" />
        </ig:XamGrid.ConditionalFormattingSettings>
        <ig:XamGrid.Columns>
            <ig:TextColumn Key="MyColumnKey">
                <ig:TextColumn.ConditionalFormatCollection>
                    <ig:EqualToConditionalFormatRule Value="Good">
                        <ig:EqualToConditionalFormatRule.StyleToApply>
                            <Style TargetType="ig:ConditionalFormattingCellControl">
                                <Setter Property="Foreground" Value="Green" />
                            </Style>
                        </ig:EqualToConditionalFormatRule.StyleToApply>
                    </ig:EqualToConditionalFormatRule>
                    <ig:EqualToConditionalFormatRule Value="Bad">
                        <ig:EqualToConditionalFormatRule.StyleToApply>
                            <Style TargetType="ig:ConditionalFormattingCellControl">
                                <Setter Property="Foreground" Value="Red" />
                            </Style>
                        </ig:EqualToConditionalFormatRule.StyleToApply>
                    </ig:EqualToConditionalFormatRule>
                </ig:TextColumn.ConditionalFormatCollection>
            </ig:TextColumn>
        </ig:XamGrid.Columns>
        ...
    

    HTH

Reply Children