Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DataBindingTutorial
- {
- public partial class Form1 : Form
- {
- BindingSource bs = new BindingSource();
- public Form1()
- {
- InitializeComponent();
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- bs.DataSource = typeof(Airplane); //**
- bs.Add(new Airplane("Boeing 747", 800));
- bs.Add(new Airplane("Airbus A380", 1023));
- bs.Add(new Airplane("Cessna 162", 67));
- grid.DataSource = bs; //**
- grid.AutoGenerateColumns = true; // create columns automatically //**
- txtModel.DataBindings.Add("Text", bs, "Model");
- }
- }
- class Airplane
- {
- public Airplane(string model, int fuelKg)
- {
- _id = ++lastID; Model = model; _fuelKg = fuelKg;
- }
- private static int lastID = 0;
- public int _id;
- public int ID { get { return _id; } }
- public int _fuelKg;
- public int FuelLeftKg { get { return _fuelKg; } set { _fuelKg = value; } }
- public string _model;
- public string Model { get { return _model; } set { _model = value; } }
- public List<Passenger> _passengers = new List<Passenger>();
- public List<Passenger> Passengers { get { return _passengers; } }
- }
- class Passenger
- {
- public Passenger(string name)
- {
- _id = ++lastID; Name = name;
- }
- private static int lastID = 0;
- public int _id;
- public int ID { get { return _id; } }
- public string _name;
- public string Name { get { return _name; } set { _name = value; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement