2014-06-15 64 views
0

我正在創建一個小型應用程序,並使用了Business Class。現在,我想創建報告。 首先,這是我的物業類別:如何在報表查看器中顯示子類 - VS 2010

public class Property 
    { 
     public int PropertyId { get; set; } 
     public int OwnerId { get; set; } 

     //User is another Class 
     public User Owner { get; set; } 

     public int StaffUserId { get; set; } 
     public Staff StaffPerson { get; set; } 

     public string Address { get; set; } 
     public int NoGarage { get; set; } 
     public int NoRoom { get; set; } 
     public int NoToilet { get; set; } 
     public string PropertyType { get; set; } 
     public string PropertyStatus { get; set; } 
     public double SalePrice { get; set; } 

     public double RentPricePerMonth { get; set; } 
     public bool IsAvailable { get; set; } 
............... 

,這裏是我的用戶類別:

public class User 
{ 
    public int UserId { get; set; } 
    public string UserName { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public string Password { get; set; } 
    public string PhoneNo { get; set; } 
    public string Email { get; set; } 

現在我想創建一個使用Property類報告,也希望顯示的User類。 我能夠顯示Property類的對象,但無法顯示用戶類。

我該怎麼做?

目前我使用這生成報告:

 Property p = Property.GetPropertyByPropertyId(propertyId); 
     PropertyBindingSource.DataSource = p; 
     reportViewer1.RefreshReport(); 

回答

0

1.implement Serializable接口,以「用戶」類

[Serializable] 
    public class User 
    { 

2.如果,如果你想顯示的用戶名,

在報告的設計中,該項目的表達設定

= Fields!Owner.Value.UserName

+0

我試過你的方式,但似乎沒有發生。 –

相關問題