Listchanged event in child BusinessListBase

Listchanged event in child BusinessListBase

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


PederSvaleng posted on Thursday, November 08, 2007

I'm trying to control my save button like this.

private void bsPatientSwitch_CurrentItemChanged( object sender, EventArgs e )
{
   
buttonSave.Enabled = aPatient.IsSavable;
}

I'm using the CurrentItemChanged on my binding source to enable/disable my save button.
The problem is when I'm adding or removing items in by child BusinessListBase nothing happens to the save button.

If I add this, ( EmploymentList is the  child BusinessListBase  )  the button works. But I don't understand why I should have to do this.

private void bsEmploymentList_CurrentItemChanged( object sender, EventArgs e )
{
   buttonSave.Enabled = aPatient.IsSavable;
}
Any suggestions on to do this without using catching the event on the bsEmploymentList_CurrentItemChanged event? Maybe it's the only way..

Thank you!

PederSvaleng replied on Thursday, November 08, 2007

private void bsEmploymentList_CurrentItemChanged( object sender, EventArgs e )
{
   buttonSave.Enabled = aPatient.IsSavable;
}
This only works when removing an Item from the list, not while adding..

--
Peder

DavidDilworth replied on Thursday, November 08, 2007

Try using the ListChanged event, rather than the CurrentItemChanged event.

As for why you have to write the handler against the list.  Well ultimately it's that BO that is raising the events in the first place.  It's not too big a problem really.

PederSvaleng replied on Friday, November 09, 2007

Thank you, David! It now works.

private void bsEmploymentList_ListChanged( object sender, ListChangedEventArgs e )
{
   
if ( aPatient != null )
   {
      
 buttonSave.Enabled = aPatient.IsSavable;
   }
}

I just had to make sure that aPatient != null.

Copyright (c) Marimer LLC