This post is based on Sheel Shah's article, called Creating a Custom Add or Edit Dialog, to which I've added some "improvements".