Click here to Skip to main content
Licence 
First Posted 3 Feb 2006
Views 26,219
Bookmarked 17 times

Observer Design Pattern for Windows Controls

By | 3 Feb 2006 | Article
The puropse of this article to implement an Observer pattern for Windows controls, with the change in data of one MDI child, How to get the other registered forms to intimate the changes.

Introduction

I was working on a health care project, and in that project I found that information about same thing can e entered from multiple MDI child forms, but if any two such forms that can add same information are opened at the same time, then if the user adds some data ion control on one form it is not updated on the related control on the other opened form.

Thats why I found a simple but really useful solution. It implements two main design Patterns, 1) Singelton 2) Observer, both patterns helped me to accomplish my task, and I think it might be useful for you people as well.

Problem Statement

Now, in the demo application I have datagrid controls on three form. Now I want if the data is added or deleted from a grid on one form it should be deleted from the other two grids as well (if the forms are created).

Solution

I came up with a simple solution, what I did was, I made a new MDI Application. Then I made three Child forms, each containing a datagrid and a Toolbar to add/delete rows. All the three child forms have been Inherited from FrmParent, that in turns has been inherited from windows.Forms.Form, FrmParent has a Public Overridable method "Update", that is called by the Ovserver class to update the changes.

Observer class is a combination os singleton and Observer design patterns. It has four methods:

1) Public Shared Function Instance() As Observer
 This is a shared method, and returns the singleton object of the class.
2) Public Sub Add(ByVal form As FrmParent)
 This method add the form tho the ArrayList.
3) Public Sub Notify(ByVal row As DataRow, ByVal op As FrmParent.Operation)
 This method intimates the registered forms to get the updates.
4) Public Sub Release(ByVal form As FrmParent)
 On form close this method is called to release the form from the ArrayList of Observer class.

Note: Open all the three forms in the application,and then start data entry, otherwise the newly adds will take effect but the previous data will not come on the new form.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

mjaleel123456

Web Developer

Pakistan Pakistan

Member

hello

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThank you. PinmemberMarc Leger6:38 24 Feb '06  
GeneralScream Pinmembernorm.net2:53 3 Feb '06  
GeneralRe: Scream PinmemberJason McBurney11:57 3 Feb '06  
GeneralRe: Scream Pinmembernorm.net20:49 6 Feb '06  
GeneralRe: Scream PinmemberJason McBurney5:25 7 Feb '06  
GeneralRe: Scream Pinmembernorm.net20:42 7 Feb '06  
GeneralRe: Scream PinmemberSecrets9:31 6 Feb '06  
GeneralRe: Scream Pinmembernorm.net20:42 6 Feb '06  
GeneralRe: Scream PinmemberSecrets8:21 8 Feb '06  
GeneralRe: Scream Pinmembernorm.net20:37 8 Feb '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 3 Feb 2006
Article Copyright 2006 by mjaleel123456
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid