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
1590
Conditional Formatting is not working for TextColumn
posted

Normal 0 false false false MicrosoftInternetExplorer4

The conditional Formatting is not working  When i bind Double or decimal type data to Xamgrid TextColumn and add the  Conditional Format to the column.

I am creating columns dynamically and applying conditional format for INT, Double and Decimal Data type data. Only for the INT column conditional Format is applied but not for others columns. I have attached the sample.

could you please review and let me know the solution. Even i tried with the unbound column but didn't got any luck.

 But when AutogenerateColumn is True for the Xamgrid than everything works fine. Could you please let me know what is the difference. If possible suggest me a best way to applying Format to the XamGrid Columns.

 

Thanks

Anil Kumar

  • 40030
    Verified Answer
    Offline posted

    Hi Anil, 

    Thanks for the sample.

    So there are a few things going on that need to be fixed in your sample

    You're hiding error messages that are getting thrown with your Try/Catches...you should remove them, b/c otherwise you would have found some of these mistakes right away.

    1.  Don't use the UnboundCOlumn for your Double column, there isn't any need:  so change it to this: 
     igGrid.Columns.Add(new TextColumn() { HeaderText = ele.Key, Key = "Properties[" + ele.Key + "].Value", ValueConverter = new DecimalConverter() }); and then fix your converter to expect the value to be the actual data. 

    2.  You're incorrectly casting the columns when looping through them:  Just cast them directly as Editable Column:

    foreach (Column coll in igGrid.Columns)

                        {

                                if (coll.HeaderText == col.ColumnName)

                                {

                                    c = coll as EditableColumn;

                                    break;

                                }

                        }

    3. Set the less.Value to the correct type: 

     LessThanConditionalFormatRule less = new LessThanConditionalFormatRule();

                                    if (col.DataType == typeof(int))

                                        less.Value = 0;

                                    else if(col.DataType == typeof(Decimal))

                                        less.Value = (decimal)0;

                                    else

                                        less.Value = 0.0;

                                    less.StyleToApply = Resources["NegativeValue"] as Style;

                                    c.ConditionalFormatCollection.Add(less);

    -SteveZ