Re: AllowNew, AddNewCore CSLA v3.0

Re: AllowNew, AddNewCore CSLA v3.0

Old forum URL: forums.lhotka.net/forums/t/3287.aspx


ozitraveller posted on Monday, July 30, 2007

Hi

I'm hoping someone can help me, I've been trying to get a Master-Detail form working for a while now without any luck. I've been through the forums so I know the all I need if to add :

AllowNew = true; to the constructor

and override AddNewCore

However I have a breakpoint in AddNewCore and it doesn't get called.

So far, the form loads correctly, apart from the missing blank row in the grid, and allows me to update the Master and/or detail records.

protected override object AddNewCore()
{
    ResidentMedicalDetail item = ResidentMedicalDetail.NewResidentMedicalDetail();
    this.Add(item);
    return item;
}

        internal static ResidentMedicalDetails NewResidentMedicalDetails()
        {
            return new ResidentMedicalDetails();
        }

     internal static ResidentMedicalDetails GetResidentMedicalDetails(SafeDataReader dr)
     {
      return new ResidentMedicalDetails(dr);
     }

        private ResidentMedicalDetails()
        {
            MarkAsChild();
            this.AllowNew = true;
            this.AllowEdit = true;
            this.AllowRemove = true;
        }

  private ResidentMedicalDetails(SafeDataReader dr)
  {
            MarkAsChild();
            Fetch(dr);
            this.AllowNew = true;
            this.AllowEdit = true;
            this.AllowRemove = true;
  }

Any help would be greatfully appreciated.

Thanks

RockfordLhotka replied on Monday, July 30, 2007

This looks OK to me, but I'd change your second ctor:

  private ResidentMedicalDetails(SafeDataReader dr)
    : this()
  {
            Fetch(dr);
  }

Same result, but cleaner code in some ways.

Perhaps your issue is in the data binding itself? How are you binding this object to your DataGridView?

ozitraveller replied on Monday, July 30, 2007

Hi Rocky

Thanks for the suggestion

Here is the code for the databinding:

        private void BindData()
        {
            MedicalCategoryInfoList medicalCategoryInfoList = null;
            CareLevelInfoList careLevelInfoList = null;
            try
            {
                using (StatusBusy busy = new StatusBusy(Common.MsgWait))
                {
                    medicalCategoryInfoList = MedicalCategoryInfoList.GetList();
                    if (medicalCategoryInfoList != null)
                        this.medicalCategoryInfoListBindingSource.DataSource = medicalCategoryInfoList;

                    careLevelInfoList = CareLevelInfoList.GetList();
                    if (careLevelInfoList != null)
                        this.careLevelInfoListBindingSource.DataSource = careLevelInfoList;

                    // main form binding source
                    if (_residentMedical != null)
                        this.residentMedicalBindingSource.DataSource = _residentMedical;
                }
            }
            catch (Csla.DataPortalException ex)
            {
                //SD.Trace.WriteLine(ex.Message + "\r\n" + ex.StackTrace + "\r\n");
                MessageBox.Show(ex.BusinessException.ToString(),
                  "Data load error", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                //SD.Trace.WriteLine(ex.Message + "\r\n" + ex.StackTrace + "\r\n");
                MessageBox.Show(ex.ToString(),
                  "Data load error", MessageBoxButtons.OK,
                  MessageBoxIcon.Exclamation);
            }
        }

            //
            // medicalDetailsBindingSource
            //
            this.medicalDetailsBindingSource.AllowNew = false;
            this.medicalDetailsBindingSource.DataMember = "MedicalDetails";
            this.medicalDetailsBindingSource.DataSource = this.residentMedicalBindingSource;
            this.BindingSourceRefresh1.SetReadValuesOnChange(this.medicalDetailsBindingSource, false);

I've been through the code for RolesEdit and ProjectEdit and everythiong seems to be ok.

 

ozitraveller replied on Wednesday, August 01, 2007

Hi Again

I've checked that the value for AllowNew in the child collection is true

            SD.Debug.WriteLine(_residentMedical.MedicalDetails.AllowNew);
            this.residentMedicalBindingSource.DataSource = _residentMedical;

And the binding for the DataGridView looks correct

            this.medicalDetailsBindingSource.DataMember = "MedicalDetails";
            this.medicalDetailsBindingSource.DataSource = this.residentMedicalBindingSource;

If set AllowNew on medicalDetailsBindingSource to true it works. But does not work otherwise.

Stumped.

ozitraveller replied on Wednesday, August 01, 2007

[Resolved]

Removed the BindingSource (medicalDetailsBindingSource) from the form and dragged a new one from the toolbox and wired it up the same way, but this time it works.

What I think happened was that when I dragged the DataSource onto the form to add the DateGridView I should have deleted that one and added a new 'clean' one and wired it up.

 

Copyright (c) Marimer LLC