Search code examples
vb.netbindingsourcereportviewer2008

How to Create Report Viewer Binding to Object in VB.NET


I have Class named "User", code:

 Public Class User

    Private m_id As String
    Private m_user_name As String

    Public Sub New(ByVal id As String, ByVal name As String, ByVal pwd As String)
      m_id = id
      m_user_name = name
      m_pwd = pwd
    End Sub

    Public Property Id() As String
      Get
          Return m_id
      End Get
      Set(ByVal value As String)
          m_id = value
      End Set
    End Property

    Public Property Name() As String
      Get
          Return m_user_name
      End Get
      Set(ByVal value As String)
          m_user_name = value
      End Set
    End Property

 End Class

And I want to report all the user's information, so I also have another class named "Users", code:

 Public Class Users
       inherits List(Of User)
       Public Sub New()
              'Query users' information from Table in Database
              Add(New User(...)
       End Sub
 End Class

When I clicked on "Print" button, it will pop up the report. I have only one Form with Report Viewer, but I have a lot of reports using this Form with Report Viewer. so I code like this:

 Public Class Form1
        Private Sub Form1_Load(...) Handles MyBase.Load

            Dim bs As New BindingSource
            bs.DataSource= New Users

            Dim rpt As New Microsoft.Reporting.WinForms.ReportDataSource
            rpt.Name = "Report_User"
            rpt.Value = bs
            ReportViewer1.LocalReport.DataSources.Add(rpt)
            ReportViewer1.LocalReport.ReportEmbeddedResource = rpt.Name
            ReportViewer1.RefreshReport()
        End Sub

But it doesn't show anything... Please help me... I really need your help.. Thanks in advance


Solution

  • Now I can resolve my problem.. Click here for reference