2 Replies - 411 Views - Last Post: 26 January 2013 - 08:31 AM Rate Topic: -----

#1 kristina1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 30-July 12

access a form's method from another form

Posted 26 January 2013 - 05:53 AM

hi,

i have a form which which loads some records in a grid view and a method which refresh these records. this form is called with the new operator each time.

i want to get from another form this refreshing method, how can i? i tried
form1.method_name()



but there is no effect as there can be opened more than one instance of form1 and the compilator dosen't know which form's method to access.

i would appreciate a lot any kind of help

Is This A Good Question/Topic? 0
  • +

Replies To: access a form's method from another form

#2 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3480
  • View blog
  • Posts: 11,845
  • Joined: 12-December 12

Re: access a form's method from another form

Posted 26 January 2013 - 08:27 AM

When you create an instance of the form you need to keep a reference to it.

Dim newForm1 As Form1 = New Form1
// then
newForm1.method_name()


So you need some way to make the variable available between the two forms, and to also handle the fact that you may have several instances of the same form.

However, this is not a good way to do this; cf. subscribing to form events. There are links and tutorials on this site.

This post has been edited by andrewsw: 26 January 2013 - 08:36 AM

Was This Post Helpful? 1
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5522
  • View blog
  • Posts: 11,830
  • Joined: 02-June 10

Re: access a form's method from another form

Posted 26 January 2013 - 08:31 AM

Quote

[*]Q: ...get Form/class 'A' to make a change or talk to Form/class 'B'

NOTE: Don't try to access GUI controls across forms. Its wrong. Nobody will hire you if you do this sort of crap. It violates every guideline for 'black box' programming, Separation of Responsibility, loose binding of components, and event driven programming. Read the tutorials and learn to do it right the first time so you don't develop bad habits that you just have to un-learn later.
A:

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1