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

How do I format a TextBox where I have put in a sum funktion?

5 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Janus Pedersen
Top achievements
Rank 2
Janus Pedersen asked on 30 Jul 2009, 09:59 PM
Hi
I am trying to make a report where I have a colum where I am using the sum- function, but I have to format the result of this colum to be a price in $. It is not working to use the normal Format property and the TextBox - object. Then my idear was to use the System.String.Format- funktion but this don`t work.

Pls. help me out.

TextBox o = new RapportDataFelt("sum(" + kolonne.KolonneNavn + ")}", kolonne.HeaderStyle).Textbox;  
o.Style.TextAlign = HorizontalAlign.Right;  
o.Style.Font.Bold = true;  
o.Format = "{0:C2}";  
Sincerely,
Janus S. Andersen
Denmark

5 Answers, 1 is accepted

Sort by
0
Janus Pedersen
Top achievements
Rank 2
answered on 30 Jul 2009, 10:16 PM
Sorry see http://www.telerik.com/community/forums/reporting/telerik-reporting/number-format.aspx It work for me for the sum and format.
var o = new RapportDataFelt("{MyFormat(sum(" + kolonne.KolonneNavn + "))}", kolonne.HeaderStyle).Textbox;  
o.Style.TextAlign = HorizontalAlign.Right; 
        public static string MyFormat(double num)  
        {  
            string format = "{0:N2}";  
            if (num < 0)  
            {  
                format = "({0:N2})";  
            }  
            return string.Format(format, Math.Abs(num));  
        }          

But I still need a way to TextAlign to the Right for the TextBox!
Pls. Help me out here.

Janus S. Andersen
0
Steve
Telerik team
answered on 31 Jul 2009, 09:29 AM
Hi Janus,

There is a slight problem with the Format Builder in the Q2 version, so it would not show the proper "Preview" pane. However entering the value manually in the property grid should work as expected (see screenshot).
The code for the horizontal alignment looks correct, and it works on our end. Have you applied it to the definition item i.e. the item in the designer?

Regards,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Janus Pedersen
Top achievements
Rank 2
answered on 31 Jul 2009, 11:44 PM
Hi Steve
Version info: Telerik Reporting 2009 Q2. IE 7.0 OS: WinXp with newest sp and opdates Lang= UK

I can not use the designer and put the value in there (the way you show is working, but not in my case). I dont know the fields name att design- time I know it att run-time. 

Thats way I put in the line

"
o.Style.TextAlign =

HorizontalAlign.Right;

 

groupFooterSection4.Items.Add(o);
"

Regards,
Janus S. Andersen
Denmark

0
Accepted
Steve
Telerik team
answered on 06 Aug 2009, 10:25 AM
Hi Janus,

We have not been able to replicate any problems with TextAlign property of the TextBox item. Please provide us with a sample report where this can be observed and we would be able to provide you with more info.

Sincerely yours,
Steve
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Janus Pedersen
Top achievements
Rank 2
answered on 06 Aug 2009, 09:46 PM
Hi Steve
It was in my code. Sorry it is working now. I have made a small sample.

 public class Test  
    {  
        public Test(int A)  
        {  
            a = A;  
        }  
 
        public int a { getset; }  
    }  
 
        private void AddTextboxToDetail(string text,bool flag)  
        {  
            var t1 = new TextBox  
                         {  
                             Height = new Unit(0.5, UnitType.Cm),  
                             Width = new Unit(8, UnitType.Cm),  
                             Dock = DockStyle.Left,  
                             Value = text,  
                             Style = {TextAlign = HorizontalAlign.Right}  
                         };  
 
            if (flag)  
            {  
                detail.Height=new Unit(0.5,UnitType.Cm);  
                detail.Items.Add(t1);      
            }  
            else 
            {  
                pageFooter.Items.Add(t1);  
                pageFooter.Height=new Unit(0.5,UnitType.Cm);  
            }  
        }  
 
       public TestRap()  
        {  
            InitializeComponent();  
            var o = new List<Test>();  
 
            for (var i = 0; i < 10; i++)  
            {  
                o.Add(new Test(i));  
            }  
 
            AddTextboxToDetail("=a",true);  
            AddTextboxToDetail("{Sum(a)}"false);  
            DataSource = o;  
        }  
    } 

I just forget I am using a TextBox to make a tap when my data is grouped and the smallest this textbox can be is 1 point.

Sorry. 
Janus S. Andersen
Denmark
Tags
General Discussions
Asked by
Janus Pedersen
Top achievements
Rank 2
Answers by
Janus Pedersen
Top achievements
Rank 2
Steve
Telerik team
Share this question
or