1。新建windows应用程序。
2。新建报表a.rdlc
3。为报表a.rdlc设置数据源
4。创建reportviewer,设置报表为a.rdlc
using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication1
{
class BusinessObjects
{
}
public class Product
{
private string m_name;
private int m_price;
public Product(string name, int price)
{
m_name = name;
m_price = price;
}
public string Name
{
get
{
return m_name;
}
}
public int Price
{
get
{
return m_price;
}
}
}
// Define Business Object "Merchant" that provides a
// GetProducts method that returns a collection of
// Product objects.
public class Merchant
{
private List<Product> m_products;
public Merchant()
{
m_products = new List<Product>();
m_products.Add(new Product("Pen", 25));
m_products.Add(new Product("Pencil", 30));
m_products.Add(new Product("Notebook", 15));
}
public List<Product> GetProducts()
{
return m_products;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form2 : Form
{
private Merchant m_merchant = new Merchant();
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
this.ProductBindingSource.DataSource = m_merchant.GetProducts();
this.reportViewer1.RefreshReport();
}
}
}