473,326 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Databinding with Nested Properties


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.

Expand|Select|Wrap|Line Numbers
  1.  
  2. txtAcres.DataBindings.Add("Text", _chemicalRecsDBS,
  3. "SiteLine.Site.CropAcres", true);
  4. txtAcres.DataBindings["Text"].Format += new
  5. ConvertEventHandler(Lib.AppCommon.DataBinding.IntFormatHandler);
  6. txtAcres.DataBindings["Text"].Parse += new
  7. ConvertEventHandler(Lib.AppCommon.DataBinding.IntParseHandler);
  8. txtAcres.DataBindings["Text"].NullValue = null;
  9.  
  10.  
_chemicalRecsDBS is bound to an IList<ChemicalRec>.

Here are the relevant class definitions:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Class ChemicalRec
  3. {
  4. public ChemicalRecSite SiteLine
  5. {
  6. get { ... }
  7. set { ... }
  8. }
  9. }
  10.  
  11. Class ChemicalRecSite
  12. {
  13. public SiteInfo Site
  14. {
  15. get { ... }
  16. set { ... }
  17. }
  18. }
  19.  
  20. Class SiteInfo
  21. {
  22. public int? CropAcres
  23. {
  24. get { ... }
  25. set { ... }
  26. }
  27. }
  28.  
  29.  


Feb 15 '07 #1
2 5329
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.

Feb 16 '07 #2
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!
Feb 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason S | last post by:
I haven't been able to get an answer to this in the asp.net group, hoping someone here can enlighten me. As pertains to databinding a control in a repeating fashion(datagrid, repeater, etc.)...
1
by: oafyuf | last post by:
Hi, I'm trying to learn ASP.NET by doing a pilot project: I have a DataGrid which contains a nested DataList. I want to iterate through the SQLDataReader for the DataGrid and populate each...
2
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can...
5
by: Trail Monster | last post by:
Ok, I've been searching the net now for several days and can't find how to do this anywhere. Version: VS 2005 Professional Release, 2.0 Framework Background: I have a complex business object...
2
by: Shane | last post by:
When I click on the DataBinding in the properties window a list of options open up called Advanced,Tag and Text. I would like to know what Tag and Text are set to? I hope to Bind a text box to a...
9
by: J055 | last post by:
Hi I have a very simple configuration of the GridView with paging and sorting. When I do a postback the DataBinding event fires twice - in both the ProcessPostData and PreRender stages of the...
1
by: CorporateCoder | last post by:
Hi, I am trying to bind the selected value of a databound dropdown box in a databound gridview control to the value being displayed in the template column the dropdown box has been added to. ...
8
by: Dirk | last post by:
Hello, I have a problem to use databinding with my business layer classes. My data class does not have simple properties (string, int or datetime), instead, all my properties are objects of the...
7
by: JTC^..^ | last post by:
When i attempt to bind to the "Text" and "Value" property of a combobox on a windows form the value is reset when I leave the combobox. The comboboxes contain the correct Text and Values. I know...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.