Marc
using System.Collections.Generic;
using System.Windows.Forms;
class Foo
{
public string Name { get; set; }
List<Bar> bars = new List<Bar>();
public List<Bar> Bars { get { return bars; } }
}
class Bar
{
public string Desc { get; set; }
}
static class Program
{
static void Main()
{
List<Foo> list = new List<Foo> {
new Foo {
Name = "Fred",
Bars = {
new Bar {Desc="abc"},
new Bar {Desc="def"}
}
}, new Foo {
Name = "Barney",
Bars = {
new Bar {Desc="ghi"}
}
}
};
Application.EnableVisualStyles();
Application.Run
(
new Form
{
Width = 600,
Text = "Linked bindings",
Controls =
{
new DataGridView {
Dock = DockStyle.Fill,
DataSource = list,
DataMember = "Bars"
},
new DataGridView
{
Dock = DockStyle.Left,
DataSource = list
}
}
}
);
}
}