IList<object> report data source

edited 5:42AM in FastReport .NET
I try to get IList<OperacjaWydruk> data source in FastReport like it is shown below. I can't cast ds.CurrentRow to OperacjaWydruk.
IList<OperacjaWydruk> ds = Report.GetDataSource("operacje") as IList<OperacjaWydruk> doesn't work for me.
Is this possible to do it with DataBand? If yes, how to do it?

Visual Studio:
raport.RegisterData((IList<OperacjaWydruk>)sprawaZmapowawna.Operacje, "operacje");
raport.GetDataSource("operacje").Enabled = true;

FRX:
public class OperacjaWydruk
  {
    public string Lp { get; set; }
    public string AudytRekorduDataModyfikacji { get; set; }
    public string OperacjaDysponentUzytkownikImie { get; set; }
    public string NazwaOperacji { get; set; }
    public string NrKancelaryjny { get; set; }
  }
  
  public class ReportScript
  {
    private void Table1_BeforePrint(object sender, EventArgs e)
    {
      DataSourceBase ds = Report.GetDataSource("operacje");
      
      if (ds != null)
      {    
        for (int i = 0; i < ds.RowCount; i++)
        {
          ds.CurrentRowNo = i;
          OperacjaWydruk ow = (OperacjaWydruk) ds.CurrentRow;
        
          TableRow tr = new TableRow();          
          TableCell tc = new TableCell();
          tc.Text = ow.Lp;
          tr.AddChild(tc);
          Text4.Text = tr.ChildObjects.Count.ToString();
          tc = new TableCell();
          tc.Text = ow.AudytRekorduDataModyfikacji;
          tr.AddChild(tc);
          tc = new TableCell();
          tc.Text = ow.OperacjaDysponentUzytkownikImie;
          tr.AddChild(tc);
          tc = new TableCell();
          tc.Text = ow.NazwaOperacji;
          tr.AddChild(tc);
          tc = new TableCell();
          tc.Text = ow.NrKancelaryjny;
          tr.AddChild(tc);
          
          Table1.Rows.Add(tr);
        }
      }
    }
  }

Comments

  • jose525jose525 Deutschland
    edited 5:42AM
    hello,
    is OperacjaWydruk your own class?
  • edited 5:42AM
    Hello,

    You should initialize the datasource before using it:
    DataSourceBase ds = Report.GetDataSource("operacje");
    if (ds != null)
    {
      ds.Init();
      ...
    

    Also you should add a reference to your .exe or .dll in which the OperacjaWydruk class is defined. You can do this in the Report/Options menu, Script tab.
  • edited April 2012
    OperacjaWydruk is my own class. Earlier, I added reference to dll which contains definition of this class so now I can cast ds.CurrentRow to OperacjaWydruk. I'm not happy with this solution but it works.

    ds.Init() is what I need. Thank you AlexTZ for your advice.

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.