Results 1 to 6 of 6

Thread: [RESOLVED] Where to setup dialog forms from

  1. #1

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Resolved [RESOLVED] Where to setup dialog forms from

    Hi Guys,

    Just a little question that doesn't really matter that much but I'm just curious how everyone else does this.

    The question is essentially: Where do you setup your dialog forms from? Do you set properties and populate items from the form that calls the dialog form or do you do it in the dialog form's Load event?

    Lets say for example I have a main form and a dialog form that lets the user add/remove some strings from a listbox that the main form then uses (and therefore the current items in the listbox should be remembered next time the dialog is shown). Would you populate the listbox with the existing strings from the main form and then show the dialog window, or would you pass the strings in to a property of the dialog window and then let that window put them into the listbox when it loads?

    I realise its not the best example because you could avoid having to do either if you just didnt dispose the dialog window, but there are numerous situations in my programs where I need to setup items on a dialog window (and dispose it when it has closed) and I currently tend to do it all from the form that is showing the dialog window. This often means I end up with a ton of code in my 'main' form if it calls several dialog windows though so it just got me wondering if other people tend to let the dialog windows do all the work themselves.

    How do you guys handle this?

    Cheers
    Chris
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Where to setup dialog forms from

    I pass the data in ... that way if I want to re-use the dialog, it works the same everywhere... if that made sense. The parent form shouldn't care what the child form does with the data. I look at it as being the same as scribbling a message, tying it to a rock, and throwing it over a wall... on the other side, you don't care what's done with the data. Same thing with data... just pass the data off to the form and let it take care of displaying the data. Besides, if you then change it from a list view to a grid... you only change the child form. If your parent form adds data to the listview, then you have to change that too.

    Make sense?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Where to setup dialog forms from

    Thanks TG, yeah that makes sense and seems like a good idea. So you would just have a property on your dialog form that accepts a string list/array (using the example from my original post) and then in the dialog form's Load event you would add those items to the listbox?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Where to setup dialog forms from

    That's exactly right. Quite frankly, no form should ever access a control on another form. One of those VB "make it easy for the beginners" things is setting the access level of anything you add in the designer to Friend by default. In C#, all components added in the form designer have their access level set to 'private', and I always change it to Private in VB too.

    It's a fundamental tenet of OOP: separate interface and implementation. When dealing with any object, you should deal with its interface only without caring about the implementation. That's basically what tg was saying. If your main form creates a dialogue that displays a list of strings then all the main form has to care about is the list of strings. What the dialogue does with that list is an implementation detail that the main form doesn't care about.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Where to setup dialog forms from

    I would do it one of three ways... parameterized constructor... Or by a SetData (or some other method) or... by exposing properties. I personally use the constructor for required information, stuff that has to be there everytime for the form, and properties for optional items.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6

    Thread Starter
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Where to setup dialog forms from

    Ah ok thanks both of you for the comments, I didn't realise C# set each control to private. Will definitely take these suggestions into account in future Cheers
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width