The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Passing data between forms

Last post 09-13-2007, 6:34 AM by pritcham. 1 replies.
Sort Posts: Previous Next
  •  09-13-2007, 6:19 AM 5081

    Passing data between forms

    Considering the scenario where there is a customer combobox displayed on a form. However, the user may not find a particular new customer on that list, so an "Add Customer" button would be placed next to this combobox that, when clicked, would open up a separate form to create a new customer. Now, when the new customer is saved in the Add Customer form, the form should close, and not only should the combobox list be updated to included the new customer record, but the new customer should also now be the selected item in the list.

    My approach thusfar has been to create a public property in the Add Customer form that could hold the key of the newly created customer record. When the new customer is saved, the key value would be stored in this public property, and the original calling form would then reference that property to refresh the combobox and select the new customer.

    My question is: Is there a better approach that would support this particular bit of functionality?

     

  •  09-13-2007, 6:34 AM 5083 in reply to 5081

    Re: Passing data between forms

    Hi

    I don't know about a 'better' approach, mine is slightly different that's all.

    Basically I only tend to have lookup type info in combo boxes as a customer list (in my domain) would be much too large to be usable in a dropdown.  So, bearing that in mind, I have the following set up:

    1) A static class that holds (effectively) a cache of the lookup collections.  This class reacts to a "NeedsRefresh" event that is generated when there are changes in the DB (in my case by using a combination of a DB trigger that runs an SQL proc that amends a file on the server, and this file is watched using a FileSystemWatcher which I use to raise the NeedsRefresh event).  If this event is raised, this class re-loads the appropriate entity collection

    2) I have an entityCombo user control class that a) uses the lookup info from the class above, b) as I don't bind directly into the combo (I add the items individually) the combo also has an [Add New] entry at the top.  If this [Add New] entry is selected it raises an "AddNewRequired" event (you can probably tell that I like events by now ;)).  The reason that I do this is that the combo could contain any one of a number of different entity types, and each entity type would potentially need a different "Add New" type form. 

    3) Basically, the form that I host the entityCombo control on reacts to the "AddNewRequired" event and calls an appropriate AddNew form.  When the AddNew form saves the new entity, the trigger on the DB alters the file, the filesystemwatcher sees that alteration and fires off a NeedsRefresh event, which causes the entity collection to be reloaded, and the combobox repopulated.  The beauty of this is that if any user (not just the one making the additions) has that combo box visible, it will be refreshed with the newly added entities (or that's the plan anyway).

    Hope that explains sufficiently - might sound a bit convoluted but I quite like it.

    Cheers

    Martin

View as RSS news feed in XML