CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2003
    Posts
    48

    Post VB.net control manipulation

    How can I manipulate a control in one form from another form? It was easy in VB 6, but in .net I can't seem to figure it out. It's not as simple as:

    formname.textbox.text = "I've got mail, yayyy!"

    Thanks for the help

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    Well it is and it isn't

    In VB6 the controls were effectively public members, in .NET they are private members.

    Most OOP developers agree (at least to some point) that data (which is effectively what the control is) should be encapsulated. One of the reasons involves object tracking and meaning. Since a control needs to always have a "parent" control or form, it would be a "bad thing" if a reference to a control was maintained after the "parent" no longer existed. This is insured by making the controls private.

    In general, it is better to add a method/property what would allow external items to access the information you desire:

    e.g:

    Sub FormWithControls.SetSpecialTest(data as string)
    MyControl.Text = data
    End Sub


    It is possible to "short circuit" this, but it is typically not wise and will tend to cause problems over the life of any significant project. Therefore the following is NOT recommended (at least by me!
    .... simply cahnge the controls variable declaration from private to public.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jan 2003
    Posts
    48

    Unhappy more...

    The reason I want to manipulate another form's controls is because I'm bringing up a 'search' form for a database... it'll have a bunch of text boxes that you could put data into to search for a specific record in a database. I want to use the connection, adapter, dataset, and sqlcommand controls off the parent form, so I don't have to duplicate.

    Any better suggestions? I could code them as methods, but that sounds like it'll get really hairy, really quick, especially when I want to fill a datagrid on the child form with data from the dataset of the parent form...

    I'm not sure how to declare a control public, btw... thanks for the help.

  4. #4
    Join Date
    May 2002
    Location
    Toronto
    Posts
    167
    are you trying to fill a datagrid with a record set ? Just declare the RecordSet in a modual and then it will be Public and you will be able to use the RecordSet to fill a datagrid on any form

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

Featured