Trying to bind to an XtraReport


Author
Message
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hya.

I am trying to bind an XtraReport label to a BO field.

Does our BO implements the IList, ITypedList or IBindingList interface? That's what the XtraReport asks me in the help file.

I get an error after I set the report DataSource to the BO :

Private Sub RelEmpresasToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RelEmpresasToolStripMenuItem.Click

Dim Report As New rptEmpresas()

Dim loEmpresas As New ProFilmeNET_BOL.boEmpresas()

loEmpresas.FillDataTable("Select * from Empresas")

Report.DataSource = loEmpresas

Report.lblNome.DataBindings.Add("Text", loEmpresas, "emp_Descr")

Report.ShowPreviewDialog()

End Sub

Any word of advice to direct me in the right direction will be appreciated.

Thanks in advance.


Replies
Paul Chase
Paul Chase
Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)Advanced StrataFrame User (806 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Ivan,

I was able to trick the Xtra Report into allowing you to drop a BusBinding Source and Bus object onto it. first create a base class report that implements IContainer. I still need to figure a few things out to make it better but below is what I have so far and seems to work. The Preview won't work but you can bind all the fields etc. But to be honest i am wondering if I even wnat to use BO's for the reports as it seems like most reports i have are base on query's with joins. But here is what I did maybe it will be helpful

Public Class XtraReportBase

Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl 'Add This Line

Public Sub New()

' This call is required by the Windows Form Designer.

InitializeComponent()

' Add any initialization after the InitializeComponent() call.

End Sub

Public Sub AddBusinessObject(ByVal BusinessObject As MicroFour.StrataFrame.Business.BusinessLayerBase) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddBusinessObject

End Sub

Public Sub AddObjectToInitOnLoad(ByVal ObjectToInit As MicroFour.StrataFrame.UI.IInitOnFormLoad) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToInitOnLoad

End Sub

Public Sub AddObjectToPreInitOnLoad(ByVal ObjectToPreInit As MicroFour.StrataFrame.UI.IPreInitOnFormLoad) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.AddObjectToPreInitOnLoad

End Sub

Public Sub RemoveBusinessObject(ByVal BusinessObject As MicroFour.StrataFrame.Business.BusinessLayerBase) Implements MicroFour.StrataFrame.UI.Windows.Forms.IContainerControl.RemoveBusinessObject

End Sub

End Class

Now go into the designer.vb file of the base report and change

Friend WithEvents Detail As DevExpress.XtraReports.UI.DetailBand

Friend WithEvents PageHeader As DevExpress.XtraReports.UI.PageHeaderBand

Friend WithEvents PageFooter As DevExpress.XtraReports.UI.PageFooterBand

to

Protected WithEvents Detail As DevExpress.XtraReports.UI.DetailBand

Protected WithEvents PageHeader As DevExpress.XtraReports.UI.PageHeaderBand

Protected WithEvents PageFooter As DevExpress.XtraReports.UI.PageFooterBand

 

Next create a new class that looks like below

Public Class InheritedReport

Inherits ReportBase.XtraReportBase ' The base class from above

Public Sub New()

InitializeComponent()

End Sub

Private Sub InitializeComponent()

End Sub

End Class

Rebuild and you should be able to get into the designer of your new subclassd report

Drop a business binding source and bus object on the form set the data source of the report to be the business binding source. The type editor of the business binding source will not work so you need to set it manually in the init component. Maybe this can figured out

Public Class InheritedReport

Inherits ReportBase.XtraReportBase

Friend WithEvents XrLabel1 As DevExpress.XtraReports.UI.XRLabel

Friend WithEvents BusinessBindingSource1 As MicroFour.StrataFrame.Business.BusinessBindingSource

Friend WithEvents BusinessObject11 As TEstBO.BusinessObject1

Private components As System.ComponentModel.IContainer

Public Sub New(Lcname as String)

InitializeComponent()

I also added the fill method here ? works

Me.BusinessObject11.FillByName(LcName)

End Sub

Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container

Me.XrLabel1 = New DevExpress.XtraReports.UI.XRLabel

Me.BusinessBindingSource1 = New MicroFour.StrataFrame.Business.BusinessBindingSource(Me.components)

Me.BusinessObject11 = New TEstBO.BusinessObject1(Me.components)

CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()

'

'Detail

'

Me.Detail.Controls.AddRange(New DevExpress.XtraReports.UI.XRControl() {Me.XrLabel1})

'

'XrLabel1

'

Me.XrLabel1.Location = New System.Drawing.Point(33, 8)

Me.XrLabel1.Name = "XrLabel1"

Me.XrLabel1.Padding = New DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100.0!)

Me.XrLabel1.Size = New System.Drawing.Size(100, 25)

Me.XrLabel1.Text = "XrLabel1"

'

'BusinessBindingSource1

'

Me.BusinessBindingSource1.ParentForm = Nothing

'Manually add Line Below

Me.BusinessBindingSource1.BusinessObject = Me.BusinessObject11

'

'BusinessObject11

'

Me.BusinessObject11.ParentContainer = Me

Me.BusinessObject11.SynchronizingObject = Nothing

CType(Me, System.ComponentModel.ISupportInitialize).EndInit()

End Sub

End Class

 

Now to call the report...

Dim rpt As New TestAppReports.InheritedReport("TEST")

rpt.ShowPreview()

 

 

 

 


Ivan George Borges
Ivan George Borges
Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)Strategic Support Team Member (4.9K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Hi Paul.

Thanks for your help!

I will study your code.

I have created an XtraReport abstract class, and in the inherited ones I've being writing code to bind the controls at runtime.

I've been able to run the reports using the BOs, but I've been creating them at runtime. I'm not binding the report controls at design time. So, I use the BOs to populate the information I need, then add them to a DataSet, working with the results there. So far, I haven't created very complex reports, yesterday I managed to make a Master-Detail report to work using the BOs in this way. But you are right, I wonder what the best practice will be when a more complex situation arrives. As usual, I think I will let Trent, Ben and Steve worry for me. BigGrin

I bet they are gonna jump in and say something.Wink

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Ivan George Borges - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ivan George Borges - 20 Years Ago
Ivan George Borges - 20 Years Ago
                     Glad you got it working, Ivan :)
StrataFrame Team - 20 Years Ago
Paul Chase - 20 Years Ago
Ivan George Borges - 20 Years Ago
Paul Chase - 20 Years Ago
Trent L. Taylor - 20 Years Ago
Ivan George Borges - 20 Years Ago
Paul Chase - 20 Years Ago
StrataFrame Team - 20 Years Ago
Paul Chase - 20 Years Ago
StrataFrame Team - 20 Years Ago
Ivan George Borges - 20 Years Ago
                         Hehe, no questions are stupid, that's for sure... and yes, you have it...
StrataFrame Team - 20 Years Ago
                             Hey, Paul. I did the changes you mentioned before to get the BO...
Ivan George Borges - 20 Years Ago
                                 Yeah I havent figured out how to make that work.. Dont hit HTML it...
Paul Chase - 20 Years Ago
                                     too late ...:D
Ivan George Borges - 20 Years Ago
                                         Ben, I understand what you are saying about using a temp table to...
Paul Chase - 20 Years Ago
                                 Hi Ivan, I'm also having problems dropping a BO onto the report...
Tim Dol - 20 Years Ago
                                     Tim you need to manually assign the bus object to the binding source...
Paul Chase - 20 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search