Hi Vanessa,
I've attached some code demonstrating how you can do this using business
objects. You should be able to do it with relational tables as well, but I'm
not so familiar using tables as datasource. The code assumes you have a
DataGridView, ComboBox and TextBox on your Form
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ClassA a = new ClassA("A");
BindingSource sourceA = new BindingSource(a, "");
BindingSource sourceB = new BindingSource(sourceA, "BList");
BindingSource sourceC = new BindingSource(sourceB, "CList");
dataGridView1.DataSource = sourceB;
comboBox1.DataSource = sourceC;
comboBox1.DisplayMember = "Name";
textBox1.DataBindings.Add("Text", sourceC, "Id");
}
}
public class ClassA
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private BindingList<ClassB> _bList;
public BindingList<ClassB> BList
{
get { return _bList; }
set { _bList = value; }
}
public ClassA(string name)
{
Name = name;
BList = new BindingList<ClassB>();
BList.Add(new ClassB(Name + " B 1"));
BList.Add(new ClassB(Name + " B 2"));
}
}
public class ClassB
{
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private BindingList<ClassC> _cList;
public BindingList<ClassC> CList
{
get { return _cList; }
set { _cList = value; }
}
public ClassB(string name)
{
Name = name;
CList = new BindingList<ClassC>();
CList.Add(new ClassC(Name + " C 1"));
CList.Add(new ClassC(Name + " C 2"));
}
}
public class ClassC
{
static int count = 0;
private string _name;
public string Name
{
get { return _name; }
set { _name = value; }
}
private int _id;
public int Id
{
get { return _id; }
set { _id = value; }
}
public ClassC(string name)
{
Name = name;
Id = count++;
}
}

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> Hi Morten!
>
[quoted text clipped - 58 lines]
> > > Thank you for any suggestion!
> > > Vanessa
Vanessa - 12 Mar 2008 18:52 GMT
Hi Morten!
Thank you for the example. It is almost what I want, but image that I put a
filter in the datagridview, just to show all names starting with "B" (in the
example all names start with "A"). In this case there will not have rows on
the grid, and the combo and textbox would be empty. How can I "clean" these
controls?
Thank you,
Vanessa
> Hi Vanessa,
>
[quoted text clipped - 161 lines]
> > > > Thank you for any suggestion!
> > > > Vanessa
Morten Wennevik [C# MVP] - 13 Mar 2008 12:26 GMT
Hi Vanessa,
I'm not sure how a DataView/Filter would work with this, but if a parent
bindingsource has no objects, the child bindingsources should clear any bound
controls as well.
If you add two buttons, move the ClassA reference to a global scope, and add
the following code to the example, clicking one button will simulate
filtering by removing all objects and the second one will add new objects.
In real life, ClassA would expose a filter property. If no items are shown
in the grid, the combobox and textbox will clear as well.
ClassA a = new ClassA("A");
private void button1_Click(object sender, EventArgs e)
{
a.BList.Clear();
return;
}
private void button2_Click(object sender, EventArgs e)
{
a.BList.Add(new ClassB("T1"));
a.BList.Add(new ClassB("T2"));
a.BList.Add(new ClassB("T3"));
return;
}
I'm afraid I can't help you on how to apply this to filtering and DataView

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> Hi Morten!
>
[quoted text clipped - 172 lines]
> > > > > Thank you for any suggestion!
> > > > > Vanessa
Vanessa - 13 Mar 2008 14:33 GMT
Hi Morten!
It is working like I wanted.
Thank you very much!
Vanessa
> Hi Vanessa,
>
[quoted text clipped - 201 lines]
> > > > > > Thank you for any suggestion!
> > > > > > Vanessa