1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private List<Person1> persons = null;
private List<string> myStrings = null;
private List<int> myInts = null;
// non bindable
private List<Person2> persons2 = null;
private void Form1_Load(object sender, EventArgs e)
{
persons = new List<Person1>();
persons.Add(new Person1("a", 1, 11));
persons.Add(new Person1("b", 2, 22));
myStrings = new List<string>();
myStrings.Add("aa");
myStrings.Add("bb");
myInts = new List<int>();
myInts.Add(1);
myInts.Add(234);
// non bindable
//persons2 = new List<Person2>();
//persons2.Add(new Person2("aa", "bb"));
//persons2.Add(new Person2("cc", "dd"));
}
private void btnPerson_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = persons;
listBox1.DataSource = persons;//sans specifier DataMembre
}
private void btnString_Click(object sender, EventArgs e)
{
listBox1.DataSource = myStrings;
}
private void btnInts_Click(object sender, EventArgs e)
{
listBox1.DataSource = myInts;
}
private void btnListPerson_Click(object sender, EventArgs e)
{
listBox1.DataSource = persons;
listBox1.DisplayMember = "P2";//avec precision du DataMembre
}
}
}
class Person1
{
public string P1 { get; set; }
public int P2 { get; set; }
public long P3 { get; set; }
public Person1(string op1, int op2, long op3)
{
this.P1 = op1;
this.P2 = op2;
this.P3 = op3;
}
}
// non bindable
class Person2
{
private string p1;
private string p2;
public Person2(string op1, string op2)
{
this.p1 = op1;
this.p2 = op2;
}
} |