Results 1 to 7 of 7

Thread: [RESOLVED][02/03] How to run another function of another form.

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Smile [RESOLVED][02/03] How to run another function of another form.

    Hi all ,
    I was stucked at this stage long time ago, since i just finished my vb6 project now i back to vb.net again.


    Old question : i found that my problem of previous thread isn't dataset problem. Perhaply, I couldn't run the function of another form.

    Example :I opened my current form with showdialog() method. I want to reload a combo box of another form when i clicked at current form such as clear the combo item and reload data from dataset.

    Thanks for your help. Your help is appreciated
    Last edited by nUflAvOrS; Sep 6th, 2007 at 10:43 PM.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: [02/03] How to run another function of another form.

    .net forms are simply classes so to run a function contained in a form, make the function public, then anything that has a reference to the form can run the function.
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [02/03] How to run another function of another form.

    Thanks Kebo,

    I did it as public function ( it was a sub instead of function )

    Example :

    Form1 :

    Code:
    
    public sub LoadCombo(ByVal ComboName as Combobox)
    ComboName.items.clear()
    
    end sub
    
    Form2 : Use to call Form 1 clear combobox itemdata

    Code:
    
    dim form1 as new Form1 
    form1.LoadCombo(form1.combo1)
    
    
    Something like this hope you can understand

    thanks you
    Last edited by nUflAvOrS; Sep 6th, 2007 at 09:14 PM.
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

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

    Re: [02/03] How to run another function of another form.

    Look at your code:
    Code:
    dim form1 as new Form1 
    form1.LoadCombo(form1.combo1)
    If you want to affect an existing Form1 object then will creating a new Form1 object help you?

    If you have a car that is out of petrol, will buying a new car and filling it with petrol affect your existing car? Of course not, because they're two different objects.

    The same goes in your code. You can have as many Form1 objects as you like. Any changes made to one of those objects affects only that object and no others, so if you create a new Form1 object and clear its ComboBox then any existing Form1 objects will be unaffected, so there ComboBoxes will remain populated.
    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

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [02/03] How to run another function of another form.

    Thanks jmc provided me the knowledge of OOP. Your explaination is quite easy to understand and very helpful for me.

    Hmm... how can I fill up my petrol instead buy a new car ?

    thanks !!
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

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

    Re: [02/03] How to run another function of another form.

    Like kebo said, anywhere you have a reference to the existing Form1 object you can call the LoadCombo method of that object. That means that if your dialogue needs to call that method then you need to pass it a reference to the object. You could do this by declaring a method or property in Form2 that accepts a Form1 object. You'd then call that method or set that property when you create the dialogue.

    That said, it is generally a sign of poor design if a modal dialogue is making changes to its caller. In almost all cases the caller should first pass any required data to the dialogue, the dialogue then does its thing and then the caller gets any required data back from the dialogue AFTER it has been dismissed.
    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

  7. #7

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: [02/03] How to run another function of another form.

    thanks jmc and kebo you all are helpful.

    I solved my problem by set a property of form1 combobox at form2. form1 pass a value to form2 combobox property.

    The problem resolved ...

    Thanks ya.......
    Where there is no hope, there can be no endeavor.

    There are two ways of rising in the world, either by your own industry or by the folly of others.

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