回复 1楼seaman的帖子
请使用以下代码测试泛型绑定:
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- List<Car> cars = new List<Car>();
- cars.Add(new Car("Ford", "Mustang", 1967));
- cars.Add(new Car("Shelby AC", "Cobra", 1965));
- cars.Add(new Car("Chevrolet", "Corvette Sting Ray", 1965));
- fpSpread1.DataSource = cars;
- fpSpread1.Sheets[0].Columns[0].DataField = "Year";
- fpSpread1.Sheets[0].Columns[1].DataField = "Model";
- fpSpread1.Sheets[0].Columns[2].DataField = "Make";
- }
- }
- [Serializable]
- public class Car
- {
- private string _make;
- private string _model;
- private int _year;
- public Car(string make, string model, int year)
- {
- _make = make;
- _model = model;
- _year = year;
- }
- public string Make
- {
- get { return _make; }
- set { _make = value; }
- }
- public string Model
- {
- get { return _model; }
- set { _model = value; }
- }
- public int Year
- {
- get { return _year; }
- set { _year = value; }
- }
- }
复制代码 |