This is a migrated thread and some comments may be shown as answers.

GridViewExpressionColumn doesn't respect DataFormatString

3 Answers 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcelo
Top achievements
Rank 1
Marcelo asked on 01 Sep 2011, 03:46 PM
Hi guys,

I'm applying the DataFormatString in codeBehind for our grid (it is dinamic) and it work very well.

I Attached a event on AutoGeneratingColumn and when it occurs, I apply everything that I need.

 (e.Column as GridViewDataColumn).DataFormatString = "#,0.00";

The problem is, that I created an ExpressionColumn, and on it, my DataFormatString doesn't work.

Here's the code:

e.Column = new GridViewExpressionColumn();
                        if(c.Mascara != null)
                            (e.Column as GridViewExpressionColumn).DataFormatString =  "#,0.00";
                        RadExpressionEditor a = new RadExpressionEditor();
                                                                  // creates the item
                        var type = ClassFactory.Instance.GetDynamicClass(Table.Columns.Select(col => new System.Linq.Dynamic.DynamicProperty(col.ColumnName, col.DataType)));
                        var item = Activator.CreateInstance(type);
 
                        foreach (var row in Table.Rows)
                        {
                            foreach (var prop in type.GetProperties())
                            {
                                if (row[prop.Name] != null)
                                {
                                    if (prop.PropertyType == typeof(DateTime?))
                                        prop.SetValue(item, new Nullable<DateTime>(Convert.ToDateTime(row[prop.Name])), null);
                                    else
                                        prop.SetValue(item, row[prop.Name], null);
                                }
                                else
                                    prop.SetValue(item, null, null);
                            }
                            break;
                        }
 
                        a.Item = item;
                        System.Linq.Expressions.Expression expression;
                        a.TryParse(c.Expressao, out expression);
                        if (expression != null)
                            (e.Column as GridViewExpressionColumn).Expression = expression;

Thanks in advance!

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 05 Sep 2011, 05:00 PM
Hi Marcelo,

 I have tested the scenario that you describe and I have found out that you should specify the DataFormatString like so:

(e.Column as GridViewExpressionColumn).DataFormatString = "{0:#,0.00}";

May you please try this and share with me if the GridViewExpressionColumn respects the DataFormatString?
Regards,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Marcelo
Top achievements
Rank 1
answered on 06 Sep 2011, 12:29 PM
Hi, Dimitrina,

You are right.

The problem is that I need change my "DataFormat pattern" just for this column.
I will do it, but if you have more thoughts to how work around this, please, let me know.
0
Accepted
Dimitrina
Telerik team
answered on 08 Sep 2011, 01:40 PM
Hello Marcelo,

 You could use the same pattern ( "{0:#,0.00}" ) for all the columns. All the GridViewDataColumns will accept this pattern.

Kind regards,
Didie
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Marcelo
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Marcelo
Top achievements
Rank 1
Share this question
or