PC Review


Reply
Thread Tools Rate Thread

Databinding with Nested Properties

 
 
Brian Pelton
Guest
Posts: n/a
 
      15th Feb 2007

I am trying to bind a textbox to the property of a property.
This code works when nested property is not null,
but it fails when nested is null.

(It fails when SiteLine.Site is null.)

The error is ArgumentNullException: component.


I setup the binding in the constructor of my Form.

Code:
txtAcres.DataBindings.Add("Text", _chemicalRecsDBS,
"SiteLine.Site.CropAcres", true);
txtAcres.DataBindings["Text"].Format += new
ConvertEventHandler(Lib.AppCommon.DataBinding.IntFormatHandler);
txtAcres.DataBindings["Text"].Parse += new
ConvertEventHandler(Lib.AppCommon.DataBinding.IntParseHandler);
txtAcres.DataBindings["Text"].NullValue = null;
_chemicalRecsDBS is bound to an IList<ChemicalRec>.

Here are the relevant class definitions:

Code:
Class ChemicalRec
{
public ChemicalRecSite SiteLine
{
get { ... }
set { ... }
}
}

Class ChemicalRecSite
{
public SiteInfo Site
{
get { ... }
set { ... }
}
}

Class SiteInfo
{
public int? CropAcres
{
get { ... }
set { ... }
}
}






 
Reply With Quote
 
 
 
 
Linda Liu [MSFT]
Guest
Posts: n/a
 
      16th Feb 2007
Hi Brian,

I performed a test based on your code and did reproduce the problem.

When we bind a control to a property of data source, the value of the bound
property in the data source could be null, e.g. in your practice, the value
of the SiteLine.Site.CropAcres could be null and there will be no
exception.

However, if the SiteLine.Site property of an instance in the data source is
null, data binding couldn't find the Site property of the SiteLine property
of the instance, so exception occurs. This behavior is by design.

A workaround to this problem is to ensure that SiteLine.Site propery is not
null.

Hope this helps.
If you have any questions, please feel free to let us know.

BTW, I will be on a long vacation from the next Monday to Friday. During my
leave, my team mates will follow up with you and it may not in time. Sorry
for the inconvenience it may bring to you!



Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
Brian Pelton
Guest
Posts: n/a
 
      16th Feb 2007
Linda Liu [MSFT] wrote:
> I performed a test based on your code and did reproduce the problem.


I had to smile when you said that. In my dealings with vendors
(PeopleSoft, Oracle, etc), usually they cannot reproduce the problem.

> However, if the SiteLine.Site property of an instance in the data source is
> null, data binding couldn't find the Site property of the SiteLine property
> of the instance, so exception occurs. This behavior is by design.


Darn. I was hoping I was just missing a step somewhere. It's so handy
to just type the full property path.


> A workaround to this problem is to ensure that SiteLine.Site propery is not
> null.


In my example, the user hasn't picked a Site yet, so it's null. I guess
I will have to hook up to an event when the Site property is populated,
and at that time, make my databindings.

I was hoping to set all the databindings in the form constructor, but as
you say it isn't possible.

Thanks for looking at this,
Brian


> BTW, I will be on a long vacation from the next Monday to Friday. During my
> leave, my team mates will follow up with you and it may not in time. Sorry
> for the inconvenience it may bring to you!


Have a great vacation!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview databinding with nested types Richard Gannon Microsoft C# .NET 2 11th Aug 2007 10:04 AM
GridView + DataBinding of nested classes SMichal Microsoft ASP .NET 1 10th Oct 2006 11:55 AM
Databinding with Nested XML =?Utf-8?B?RGF2ZQ==?= Microsoft Dot NET 0 18th Mar 2004 08:26 AM
Problems with Databinding, with nested objects properties Maximiliano Microsoft Dot NET Framework Forms 0 2nd Nov 2003 05:39 AM
Databinding with Nested Objects Victor Jones Microsoft Dot NET Framework Forms 3 30th Oct 2003 06:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.