[RESOLVED][02/03] How to run another function of another form.
Hi all :wave: ,
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:thumb:
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.
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 :)
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.
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 !!
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.
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.......