Problems with report from code

Hello all!

At our company we have just started using fastreports component for .net and we encounter the folowing problem:
If i try to build a report from code ( without a datasource , because i don't need one in this very instance ) and actually place fastreport objects on a band , the object just don't appear.
Also the ones that do appear don't respect the ".left",".top" proprieties which i am setting in code.......

The main point is to draw some objects ( usually TextObject in such a way that is resembles a WBS structure from Project Management theory ) on a databand like on a canvas. The following code is not doing what is it supposed to do when u "read" the code...
raportWBS = New FastReport.Report
        Dim cm As Single = FastReport.Utils.Units.Centimeters
        Dim page As New FastReport.ReportPage : page.Name = "Pagina"
        raportWBS.Pages.Add(page)

        page.ReportTitle = New FastReport.ReportTitleBand : page.ReportTitle.Name = "TitluRaport" : page.ReportTitle.Height = 1.5F * cm : page.Landscape = True

        Dim groupHeaderBand As New FastReport.GroupHeaderBand : groupHeaderBand.Name = "GrupHeader" : groupHeaderBand.Height = 1.0F * cm
        page.Bands.Add(groupHeaderBand)
        groupHeaderBand.GroupFooter = New FastReport.GroupFooterBand : groupHeaderBand.GroupFooter.Name = "GrupFooter" : groupHeaderBand.GroupFooter.Height = 1.0F * cm
        Dim bandaPrincipala As New FastReport.DataBand : bandaPrincipala.Name = "BandaPrincipala" : bandaPrincipala.Height = 10.0F * cm
        groupHeaderBand.Data = bandaPrincipala

        Dim txtTitlu As New FastReport.TextObject : txtTitlu.Name = "txtTitlu" : txtTitlu.Text = "Ceva"
        txtTitlu.Font = New Font("Tahoma", 14, FontStyle.Bold)
        txtTitlu.HorzAlign = FastReport.HorzAlign.Center : txtTitlu.VertAlign = FastReport.VertAlign.Center
        txtTitlu.Height = 1 * cm : txtTitlu.Width = 3 * cm
        page.ReportTitle.Objects.Add(txtTitlu)

        Dim txtInv As New FastReport.TextObject : txtInv.Name = "txtInv" : txtInv.Text = _dtTask.Select("Tip = 'Inv'")(0)("Denumire").ToString
        txtInv.Font = New Font("Tahoma", 12, FontStyle.Bold)
        txtInv.HorzAlign = FastReport.HorzAlign.Center : txtInv.VertAlign = FastReport.VertAlign.Center
        txtInv.Border.Lines = FastReport.BorderLines.All
        txtInv.Height = 1 * cm : txtInv.Width = 4 * cm

        groupHeaderBand.Data.Objects.Add(txtInv)




        raportWBS.Show()

The "txtTitlu" object does appear on the report preview but the second object does not.
Also if i open the designer after running the code , the second object is not there and i don't see the title band, groupheader band, databand and the footer band I only see a a big "Overlay" grey band even if a inserted 3 bands in the code above ( following the tutorial for report from code).


If the code/ ideea for creating what i want is wrong , that's ok but i need an alternative from you guys. Keep in mind that i need to be able to move/align the TextObject on the databand at the runtime and place variable number of them on the band depending on the information i have
Thanks!

Comments

  • edited 5:29AM
    Hi all!

    In the mean time i found a solution and for anyone ho is gone be in the same situation here it is:

    1. First use a blank report with ReportTitle band, PageHeader band, Data Band and Page footer band ( fastreport tehnical support suggested that [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> ) 2. The settings from "1" will allow us to draw on the band but still the page height/width refuses to set corectly so use "unlimitedHeight" and "unlimitedWidth" on the Page properties 3. I used the "Data_BeforePrint" event of the databand event to draw/place/construct everything i needed . Here is the code example :[/img]
    private void Data1_BeforePrint(object sender, EventArgs e)
        {
          List<TextObject>  matriceObiecte =  new List<TextObject>();
          Single latimeNecesara = 0;
          Single mostRightObject = 0;
          Single spatiuObiecte = 50;
          
          TextObject txtInv = new TextObject();
          
          txtInv.Width = 4F *  Units.Centimeters;
          txtInv.Height = 0.5F * Units.Centimeters;
          txtInv.Text = "Investitie__";
          txtInv.Visible = true;
          txtInv.Border.Lines = BorderLines.All;
          
          txtInv.Top = 20;  
          
          Data1.Objects.Add(txtInv);
          for(int i = 0; i<15; i++){
            TextObject Obiect_x  = new TextObject();      
            Obiect_x.Width = 3.0F *  Units.Centimeters;
            Obiect_x.Height = 0.5F * Units.Centimeters;
            Obiect_x.Text = "Obiect__" + i.ToString();
            Obiect_x.Visible = true;
            Obiect_x.Border.Lines = BorderLines.All;
            Obiect_x.Top = txtInv.Bottom + 30;
            
            
            matriceObiecte.Add(Obiect_x);        
            if(i==0){
              Obiect_x.Left = 1 *  Units.Centimeters;
            }
            else{
              Obiect_x.Left = ( matriceObiecte[i-1].Right + spatiuObiecte ); 
            }
            Data1.Objects.Add(Obiect_x);
            latimeNecesara+= Obiect_x.Width;
            mostRightObject = Obiect_x.Right;
            
            List<TextObject> matriceDevize = new List<TextObject>();
            
            for(int j = 0; j < 30; j++){
              TextObject Deviz_x  = new TextObject();
              Deviz_x.Width = 2.5F *  Units.Centimeters;
              Deviz_x.Height = 0.5F * Units.Centimeters;
              Deviz_x.Text = "Deviz__" + i.ToString() + j.ToString();
              Deviz_x.Visible = true;
              Deviz_x.Border.Lines = BorderLines.All;
              Deviz_x.Left = Obiect_x.Left + Obiect_x.Width/2;
              matriceDevize.Add(Deviz_x);
              if(j==0){
                Deviz_x.Top = Obiect_x.Bottom + 10;
              }
              else{
                Deviz_x.Top = matriceDevize[j-1].Bottom + 10;
              }
              Data1.Objects.Add(Deviz_x);
            }
          }
          txtInv.Left = mostRightObject/2 - Units.Centimeters;
        }
    

    Have a nice day!

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.