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
515
XamGrid - Creating conditional format column from code doesn't work
posted

I have a situation where I need to create/configure a conditional format column in code, but my code version will not render my conditional icons like the XAML version does. Here's what my grid with conditional format looks like in XAML:

<ig:XamGrid Name="theGrid" AutoGenerateColumns="False">
    <ig:XamGrid.ConditionalFormattingSettings>
        <ig:ConditionalFormattingSettings AllowConditionalFormatting="True"/>
    </ig:XamGrid.ConditionalFormattingSettings>
    <ig:XamGrid.Columns>
        <ig:TemplateColumn HeaderText="Status" Key="SomeStatus">
            <ig:TemplateColumn.ConditionalFormatCollection>
                <ig:IconConditionalFormatRule RuleExecution="None" IsTerminalRule="True">
                    <ig:IconConditionalFormatRule.Rules>
                        <ig:ConditionalFormatIcon ValueType="Number" Value="2" Operator="GreaterThanOrEqualTo">
                            <ig:ConditionalFormatIcon.Icon>
                                <DataTemplate>
                                    <Image Source="/AppNamespace;component/Images/image2.png" />
                                </DataTemplate>
                            </ig:ConditionalFormatIcon.Icon>
                        </ig:ConditionalFormatIcon>
                        <ig:ConditionalFormatIcon ValueType="Number" Value="1" Operator="GreaterThanOrEqualTo">
                            <ig:ConditionalFormatIcon.Icon>
                                <DataTemplate>
                                    <Image Source="/AppNamespace;component/Images/image1.png" />
                                </DataTemplate>
                            </ig:ConditionalFormatIcon.Icon>
                        </ig:ConditionalFormatIcon>
                    </ig:IconConditionalFormatRule.Rules>
                </ig:IconConditionalFormatRule>
            </ig:TemplateColumn.ConditionalFormatCollection>
        </ig:TemplateColumn>
    </ig:XamGrid.Columns>
</ig:XamGrid>

Here's the attempt of creating this in code:

var templateColumn = new TemplateColumn();
templateColumn.Key = "SomeStatus";
templateColumn.HeaderText = "Status";
templateColumn.ConditionalFormatCollection = new ConditionalFormatCollection();
               
var iconFormatRule = new IconConditionalFormatRule() {
    RuleExecution = Infragistics.EvaluationStage.AfterFilteringAndPaging,
    IsTerminalRule = true
};

// Create icon 2's condition.
var image2 = new ConditionalFormatIcon
{
    ValueType = IconRuleValueType.Number,
    Value = 2,
    Operator = IconGroupOperator.GreaterThanOrEqualTo
};
image2.Icon = (DataTemplate)XamlReader.Load("<DataTemplate xmlns=\"http://schemas.microsoft.com/client/2007\"><Image Source=\"/AppNameSpace;component/Images/image2.png\" /></DataTemplate>");
iconFormatRule.Rules.Add(image2);

// Create icon 1's condition.
var image1 = new ConditionalFormatIcon
{
    ValueType = IconRuleValueType.Number,
    Value = 1,
    Operator = IconGroupOperator.GreaterThanOrEqualTo
};
image1.Icon = (DataTemplate)XamlReader.Load("<DataTemplate xmlns=\"http://schemas.microsoft.com/client/2007\"><Image Source=\"/AppNameSpace;component/Images/image1.png\" /></DataTemplate>");
iconFormatRule.Rules.Add(image1);

theGrid.Columns.Add(templateColumn);

Does anyone know why this would not work when constructing the equivalent template column w/conditional format in code?

Thanks,

John

 

 

Parents
No Data
Reply
  • 30945
    Suggested Answer
    Offline posted

    Hello,

     

    I have been looking into the issue that you have described and I could not manage to reproduce it. I have created a sample application in which I am adding a TemplateColumn with conditional formatting applied in code. I have tested the sample application with both build 11.1.20111.1004 and the latest service release and the condition formatting is applied.

     

    Please let me know if you can reproduce the behavior that you have described with my sample application or I have misunderstood you in any way.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

     

     

    CondFormattingInCode.zip
Children