problems binding EntityCollection to C# ComboBox

Posts   
 
    
Aaron
User
Posts: 7
Joined: 31-May-2007
# Posted on: 31-May-2007 01:24:18   

LLBLGEN Ver 2.0.0.0 Final Microsoft Visual C# 2005

I have a two forms ActionPlanList and ActionPlanWizard. ActionPlanList contains a dataGridView with columns displaying various properties of an ActionPlanEntity. It also contains a button that opens a non-modal ActionPlanWizard. An ActionPlanWizard is a wizard form that steps a user through the process of populating an ActionPlanEntity. Once the user has stepped through the ActionPlanWizard the action plan is displayed in the dataGridView on the ActionPlanList. The ActionPlanWizard contains two ComboBoxes...'Business Area' and 'Focus Area'. I have bound an EntityCollection directly to these ComboBoxes which is populated from our database. I have also bound an entity collection containing 'Business Area' and 'Focus Area' to the dataGridView displayed in the ActionPlanList. The dataGridView is displaying a property that I have added to the AdditionsToGeneratedCode. You can see the properties below. When I open more than one ActionPlanWizard I get the following errors (I have attached the screen shots). I can click Ok to this dialog and there seems to be no adverse effect to the way my application runs. I have attempted to handle the DataError event but have found no luck understanding how. Can you assist in any way?

Properties I have added to AdditionsToGeneratedCode of a ActionPlanEntity


        public string BusinessAreasRef
        {
            get
            {
                return this.BusinessAreas.Description; //(line 136)
            }
        }

        public string FocusAreasRef
        {
            get
            {
                return this.FocusAreas.Descrition; //(line 144)
            }
        }

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 31-May-2007 03:26:48   

Hi Aaron,

Not sure but It seems to be related with a null reference of BusinessAreas or FocusAreas.

You may add some validation to ensure BusinessAreas or FocusAreas aren't null, coz the this.BusinessAreas.Description line will return "object not reference ..." if BusinessAreas is null.

You can add something like:

 public string BusinessAreasRef
        {
            get
            {
                string toReturn = "";
                if (this.BusinessAreas != null)
                {
                toReturn = this.BusinessAreas.Description; //(line 136)
                }       

                return toReturn; 
            }
        }

However, if you are pretty sure BusinessAreas never will become null, you need to review your prefetch routine (if you are using Adapter).

David Elizondo | LLBLGen Support Team