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

6 posts, 1 answers
  1. Janus Pedersen
    Janus Pedersen avatar
    34 posts
    Member since:
    Dec 2008

    Posted 30 Jul 2009 Link to this post

    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.

    1 TextBox o = new RapportDataFelt("sum(" + kolonne.KolonneNavn + ")}", kolonne.HeaderStyle).Textbox;  
    2 o.Style.TextAlign = HorizontalAlign.Right;  
    3 o.Style.Font.Bold = true;  
    4 o.Format = "{0:C2}";  
    5
    Sincerely,
    Janus S. Andersen
    Denmark
  2. Janus Pedersen
    Janus Pedersen avatar
    34 posts
    Member since:
    Dec 2008

    Posted 30 Jul 2009 Link to this post

    Sorry see http://www.telerik.com/community/forums/reporting/telerik-reporting/number-format.aspx It work for me for the sum and format.
    1 var o = new RapportDataFelt("{MyFormat(sum(" + kolonne.KolonneNavn + "))}", kolonne.HeaderStyle).Textbox;  
    2 o.Style.TextAlign = HorizontalAlign.Right; 
    1         public static string MyFormat(double num)  
    2         {  
    3             string format = "{0:N2}";  
    4             if (num < 0)  
    5             {  
    6                 format = "({0:N2})";  
    7             }  
    8             return string.Format(format, Math.Abs(num));  
    9         }          

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

    Janus S. Andersen
  3. DevCraft banner
  4. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 31 Jul 2009 Link to this post

    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.
  5. Janus Pedersen
    Janus Pedersen avatar
    34 posts
    Member since:
    Dec 2008

    Posted 31 Jul 2009 Link to this post

    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

  6. Answer
    Steve
    Admin
    Steve avatar
    10941 posts

    Posted 06 Aug 2009 Link to this post

    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.
  7. Janus Pedersen
    Janus Pedersen avatar
    34 posts
    Member since:
    Dec 2008

    Posted 06 Aug 2009 Link to this post

    Hi Steve
    It was in my code. Sorry it is working now. I have made a small sample.

    1  public class Test  
    2     {  
    3         public Test(int A)  
    4         {  
    5             a = A;  
    6         }  
    7  
    8         public int a { getset; }  
    9     }  
    10  
    1         private void AddTextboxToDetail(string text,bool flag)  
    2         {  
    3             var t1 = new TextBox  
    4                          {  
    5                              Height = new Unit(0.5, UnitType.Cm),  
    6                              Width = new Unit(8, UnitType.Cm),  
    7                              Dock = DockStyle.Left,  
    8                              Value = text,  
    9                              Style = {TextAlign = HorizontalAlign.Right}  
    10                          };  
    11  
    12             if (flag)  
    13             {  
    14                 detail.Height=new Unit(0.5,UnitType.Cm);  
    15                 detail.Items.Add(t1);      
    16             }  
    17             else 
    18             {  
    19                 pageFooter.Items.Add(t1);  
    20                 pageFooter.Height=new Unit(0.5,UnitType.Cm);  
    21             }  
    22         }  
    23  
    1        public TestRap()  
    2         {  
    3             InitializeComponent();  
    4             var o = new List<Test>();  
    5  
    6             for (var i = 0; i < 10; i++)  
    7             {  
    8                 o.Add(new Test(i));  
    9             }  
    10  
    11             AddTextboxToDetail("=a",true);  
    12             AddTextboxToDetail("{Sum(a)}"false);  
    13             DataSource = o;  
    14         }  
    15     } 

    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
Back to Top
DevCraft banner