You need to set exactly the same DataSource for each, and use DataMember
(on the second grid) to specify the property to use to obtain the
sub-data. This ensures that the same "currency manager" is used when
binding the outer items; here's a C# 3 example, but works the same in C#
2...
Marc
using System.Collections.Generic;
using System.Windows.Forms;
class Foo
{
public string Name { get; set; }
List<Barbars = new List<Bar>();
public List<BarBars { get { return bars; } }
}
class Bar
{
public string Desc { get; set; }
}
static class Program
{
static void Main()
{
List<Foolist = 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
}
}
}
);
}
}