Hi,
It took me a while to crack this one as indeed it only worked in the
constructor. However, you have mixed the order of DataSource and DataMember.
Add the DataSource before the DataMember. Usually this would work fine as
the existance of the DataMember is resolved if you later set the DataSource,
but apparantly not with relations, and the DataMember would consistently get
reset when dataGridView2 got its DataSource when the code ran outside the
constructor.
The reason why this worked in the constructor is probably due to the fact
that databindings aren't fully implemented until the controls are actually
created, and the DataGridViews aren't created at constructor time (Created
property is false). When they later got created it didn't really matter if
you added the DataSource or DataMember first as the code for the DataSource
probably ran first anyway. This is the reason why you shouldn't set up
DataBindings in the constructor.

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> For a form that has two DataGridView controls, I find following piece of
> code (free of bindingsource, binding navigator, typed dataset etc
[quoted text clipped - 58 lines]
> dataGridView2.DataMember = "Customers.Customer_Orders";
> dataGridView2.DataSource = dataSet;
Mansoor A. Karim - 10 Jul 2008 04:58 GMT
Thanks Morten for help.
I have checked and indeed the DataMember gets reset when the
DataSource/DataMember sequence is mixed. Just wondering, I never came across
this order significance in the documentations.
I have another similar code relocation problem that I am posting separately
and would appreciate if you could please also crack this one for me.
> Hi,
>
[quoted text clipped - 84 lines]
>> dataGridView2.DataMember = "Customers.Customer_Orders";
>> dataGridView2.DataSource = dataSet;
Morten Wennevik [C# MVP] - 10 Jul 2008 07:50 GMT
Hi,
When stepping into the framework code it seems to boild down to this.
When setting DataMember before DataSource, the DataGridView fails to create
a CurrencyManager with a DataBinding for this DataMember since the DataSource
is null.
When setting DataSource, it detects the existing DataMember, but since the
CurrencyManager does not contain a DataBinding for this DataMember, the
DataMember is considered invalid and sets this.DataMember = "";
I haven't checked the code at constructor time, though, as somehow I cannot
load the framework code in my code sample then.
If you have Visual Studio 2008 (not express) you can step into framework
code, including DataGridView code. See this article or google for "step into
framework code" for more info:
[Configuring Visual Studio to Debug .NET Framework Source Code
http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-deb
ug-net-framework-source-code.aspx

Signature
Happy Coding!
Morten Wennevik [C# MVP]
> Thanks Morten for help.
>
[quoted text clipped - 93 lines]
> >> dataGridView2.DataMember = "Customers.Customer_Orders";
> >> dataGridView2.DataSource = dataSet;
Mansoor A. Karim - 11 Jul 2008 08:28 GMT
Thanks for the link on stepping into framework code.
Unfortunately I am still using VS2005 (not express edition) but am planning
to upgrade to 2008 shortly. Will refer back to the link then as I have
checked and the feature probably does not apply to VS2005.
> Hi,
>
[quoted text clipped - 135 lines]
>> >> dataGridView2.DataMember = "Customers.Customer_Orders";
>> >> dataGridView2.DataSource = dataSet;