2016-07-17 9 views
2

私は単純なクラスを持っています。このクラスでレポートを作成したいと思います。devExpress ReportWizardを使用してレポートを作成し、オブジェクトにバインドする方法

public class report 
{ 
    public string userName { get; set; } 
    public string userVardNo { get; set; } 
    public string userMobile { get; set; } 
    public string userBirthDay { get; set; } 
    public int totalHours { get; set; } 
    public int totalMinutes { get; set; } 
    public int totalDays { get; set; } 
    public string monthName { get; set; } 
    public string reportDateTime { get; set; } 
    public string totalPrice { get; set; } 
    public string pricePerHour { get; set; } 
} 

そして、これは私がステップによって報告ステップを作成する方法である:これは私のクラスである

プロジェクト - >新しいアイテム - > DevExpress社のV XXレポートウィザード - を追加> 、このダイアログが開きます。 をenter image description here

データバインドレポートを選択します。次に: enter image description here

私はオブジェクトバインディングを選択します。その後、私は私のレポートクラスを選択し、データソースのスキーマを取得選択します。(私は両方試してみましたが、無駄で)

enter image description here

その後、私はそうのすべてのフィールドを選択します。全て大丈夫。私は自分のレポートをデザインして閉じます。 enter image description here

私はフォームを作成します。ドキュメントビューアを追加します。フォームコンストラクタクラスでは、次の行を記述します。

public report_form() 
    { 
     InitializeComponent(); 
     report report_class = new report(); 
     report_class.userName = "Soup MacTavish";report_class.userMobile = "555-987654";//And so on... 
     XtraReport1 report_1 = new XtraReport1(); 
     report_1.DataSource = report_class; 
     documentViewer1.DocumentSource = report_1; 
     documentViewer1.Refresh(); 
    } 

私のプログラムを実行してもデータは表示されません。私はこのエラーを取得する:

enter image description here

私はこのように私のレポートで使用するデータソースインタフェースを継承するために、私のレポートクラスを変更:

public class report: DevExpress.DataAccess.ObjectBinding.ObjectDataSource 
{ 
    public string userName { get; set; } 
    public string userVardNo { get; set; } 
    public string userMobile { get; set; } 
    public string userBirthDay { get; set; } 
    public int totalHours { get; set; } 
    public int totalMinutes { get; set; } 
    public int totalDays { get; set; } 
    public string monthName { get; set; } 
    public string reportDateTime { get; set; } 
    public string totalPrice { get; set; } 
    public string pricePerHour { get; set; } 
} 

この時エラーがなくなっているが、データがありません可視。

enter image description here

どのように私はクラスにバインドされたレポートを作成することができますか?

答えて

2

最初は、Microsoft Styleguideを使用することをお勧めします。クラス名大文字(レポート)などを書く。 Microsoft C# Codeconventions

しかし、今問題が発生しました。私の知る限り、リストを使用する必要があります。 BindingList、ReadOnlyCollectionなども同様ですが、簡単にしましょう。 データバインディングのために、次のコードを試してみてください。

List<Report> dummyList = new List<Report>(); 
dummyList.Add(new Report()); 
XtraReport myReport = new XtraReport(); 
myReport.DataSource = dummyList; 

これはあなたのために働く必要があります。クラスはインターフェイスを実装する必要はありません。

+0

ありがとうございました。正解/- - –

関連する問題