Using methods from another Form C#

Hello!
I'm having some trouble using methods from one Form in another one. Here's the deal:
This is a snippet from my 'main' form:
public partial class PRINCIPAL : Form
//some variables here
Form2 Config = new Form2();
Form3 Cadastro = new Form3();
public PRINCIPAL()
InitializeComponent();
//code goes on and on
//Here's the method I want to call on the other forms (Form2 and Form3)
public void salva_banco()
this.Validate();
this.projetoBindingSource.EndEdit();
this.modulosBindingSource.EndEdit();
this.funcaoBindingSource.EndEdit();
this.estadosBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.database1DataSet);
//And here is where I show Form3
private void projetoDataGridView_CellDoubleClick_1(object sender, DataGridViewCellEventArgs e)
Cadastro.ShowDialog();
//And here is where I show Form2
private void funcaoDataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
Config.ShowDialog();
}// And the code keeps on going}
And this is a snippet from Form3:
public partial class Form3 : Form
public Form3()
InitializeComponent();
private void Form3_Load(object sender, EventArgs e)
this.projetoTableAdapter.Fill(this.database1DataSet.Projeto);
this.modulosTableAdapter.Fill(this.database1DataSet.Modulos);
private void btnOK_Click(object sender, EventArgs e)
if (projetoTextBox.Text == "")
MessageBox.Show("some text here");
else
////// HERE IS THE PLACE WHERE I WANT TO CALL THE METHOD! "salva_banco()"
I've read lots of suggestions but none satisfied my condition.
I appreciate any help.
Thanks.

You need to find the instance of the PRINCIPAL form to call the method on.  If you know there will always be exactly one open you can use:
var principalForm = Application.OpenForms.OfType<PRINCIPAL>().Single();
principalForm.salva_banco();
David
David http://blogs.msdn.com/b/dbrowne/

Similar Messages

  • Use a method from another class in another package?

    How can I use a method from another class in another package?

    WhiteJ wrote:
    What do you mean by "new keyword?" You posted this previously:
    I tried that, it seems to not be working. I want to use the constructor from the other class. I imported it, using this piece of code:
    import components.FileChooser;
    components.FileChoser();
    Typically if I am going to call a constructor on a class called Fubar, I'd use new to create a new object:
    Fubar myFubar = new Fubar();Incidently, is it a simple typo in your post or are you trying to use a FileChoser object when it should be FileChooser?

  • Control access of a form from another form.

    hi all,
    Please help me .
    This is a system which contains a lot of forms (more than 100) . The system administrator can specify whether a user can insert, update,delete or query for each form (this varies for each user). So, when a user logs in and calls a form i have to enable / disable the insert, update,delete or query according to the user who has logged in and the privileges the system administrator has given for that form.
    i used the call_form method with query_only mode and no_query_only(normal mode) option . The normal mode allows insert,update,delete and query together but i want the user to insert into database without querying any of the records.
    So, in short , i would like to know if i can enable/disable insert,update,delete & query of a called form(Form B) from calling form (Form A) without having to modify (Form B) and without issuing any grant statements in the database side ? Is there any option like the one in the call form method?
    Thanking you in advance.

    Thank you very much for the response.
    yes, set form property and set block property can be used when i want to enable / disable insert in the current form. But, what if i want to control enable/disable insert from another form (the main form) ????
    Can i pass parameters ? without making any change in the current form.

  • Frm-92101 happens when I open a form from another form and close it.

    Frm-92101 happens when I open a form from another form, check something, show a message to the user and exit the form to the previous form.
    Forms version: 10.1.2.0.2. Java: 1.6.0_23. Browser: IE6
    When I put before the "EXIT_FORM" two messages, everything is fine and the second form is closed and I repeat to the first form just as I wanted.
    In forms 9.0 it didn't happen.
    Does it have a connection with the fact I use JRE instead of JInitiator?
    Thank you.

    >
    There are numerous causes of the FRM-92101 error. I recommend you start your investigation by tracing your Forms session so you can see what your form is doing when the error occurs. Check out My Oracle Support document How to Use Forms Trace with Forms [ID 209372.1] for information on how to enable the trace. Also, take a look at My Oracle Support document Known Causes of FRM-92101 Error In Forms [ID 604633.1].
    Hope this helps,
    Craig
    >
    I have just found that there is a "Synchronize" command in one of the main attached libraries, and when I comment that command the application works well. But I don't want to comment it because it's a great library and I assume it has a part in the system.
    I have discovered that in the new Forms' help, the fact that the System.Current_Item mustn't be null so the command "Synchronize" will work, is mentioned. In the old Forms' help, that fact is not mentioned.
    So I tried to put it inside a condition that checks if the current item is not null, but the compiler doesn't recognize the "current_item". I don't know why. Because it's a library? So how can I check this? I can sent it as a parameter, but I don't want. Do you know something about it? Thank you.

  • Opening & pre-populating a form from another form

    I am designing a form with Designer 7.0 whereby the user enters data into repeating subforms. This data is used to populate another form which repeats according to the number of instances created in the first form. I am wanting to create a button on the first form which the user can click so that the second form is opened and already populated with the data from the first form (which remains open). I am unsure how to go about this. Can anyone suggest some script which would get me started?

    You could also use OPEN_FORM(form_name,ACTIVATE,SESSION). This opens the second form in an independent session which will allow you to toggle between forms and commit on a single form only.
    Creating independent sessions is usually appropriate for forms that access different tables and independent logical transactions.
    The Oracle Forms Runform must be running with the Session option turned on when you use the session parameter in the OPEN_FORM call.
    Dpending upon your requirement, you may use OPEN_FORM or as Bogdan suggested use the RUN_PRODUCT with ASYNCHRONOUS option.

  • HOW TO CALL A FORM FROM ANOTHER FORM

    HOW TO CALL A FORM FROM ANOTHER FORM [local machine]

    Balraj wrote:
    HOW TO CALL A FORM FROM ANOTHER FORM [local machine]The way you asked question is this bit of request or order?
    Secondly, you used capital latters which are being treated as Shouting Language. So, always try to switch off the Capslock of your keyboard.
    Thirdly, you are very lazy to serach on forum or google for your problem instead of waiting someone to anwer your question.
    Your should seriously have a look at FAQ.
    http://wikis.sun.com/display/Forums/Forums+FAQ
    Also here.
    http://www.catb.org/~esr/faqs/smart-questions.html
    Please read documentation for the initial questions.
    -Ammad

  • File upload hanging when called from another form

    Hi
    I have created a file upload form from the documentation I found on metalink and the form works fine on its own. I have then implemented the form into a multi form application and when the file upload form is called from another form it hangs trying to get to the client drive so that it can pick up a file. I have tried using the 'call_form', 'open_form' and 'new_form' built-ins but the results were all the same. Can anybody help me?
    Maria

    Hello,
    This is not the support, so there are no post more urgent than other.
    Francois

  • Is it possible to call methods from another class from within an abstract c

    Is it possible to call methods from another class from within an abstract class ?

    I found an example in teh JDK 131 JFC that may help you. I t is using swing interface and JTable
    If you can not use Swing, then you may want to do digging or try out with the idea presented here in example 3
    Notice that one should refine the abstract table model and you may want to create a method for something like
    public Object getValuesAtRow(int row) { return data[row;}
    to give the desired row and leave the method for
    getValuesAt alone for getting valued of particaular row and column.
    So Once you got the seelcted row index, idxSelctd, from your table
    you can get the row or set the row in your table model
    public TableExample3() {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    // Take the dummy data from SwingSet.
    final String[] names = {"First Name", "Last Name", "Favorite Color",
    "Favorite Number", "Vegetarian"};
    final Object[][] data = {
         {"Mark", "Andrews", "Red", new Integer(2), new Boolean(true)},
         {"Tom", "Ball", "Blue", new Integer(99), new Boolean(false)},
         {"Alan", "Chung", "Green", new Integer(838), new Boolean(false)},
         {"Jeff", "Dinkins", "Turquois", new Integer(8), new Boolean(true)},
         {"Amy", "Fowler", "Yellow", new Integer(3), new Boolean(false)},
         {"Brian", "Gerhold", "Green", new Integer(0), new Boolean(false)},
         {"James", "Gosling", "Pink", new Integer(21), new Boolean(false)},
         {"David", "Karlton", "Red", new Integer(1), new Boolean(false)},
         {"Dave", "Kloba", "Yellow", new Integer(14), new Boolean(false)},
         {"Peter", "Korn", "Purple", new Integer(12), new Boolean(false)},
         {"Phil", "Milne", "Purple", new Integer(3), new Boolean(false)},
         {"Dave", "Moore", "Green", new Integer(88), new Boolean(false)},
         {"Hans", "Muller", "Maroon", new Integer(5), new Boolean(false)},
         {"Rick", "Levenson", "Blue", new Integer(2), new Boolean(false)},
         {"Tim", "Prinzing", "Blue", new Integer(22), new Boolean(false)},
         {"Chester", "Rose", "Black", new Integer(0), new Boolean(false)},
         {"Ray", "Ryan", "Gray", new Integer(77), new Boolean(false)},
         {"Georges", "Saab", "Red", new Integer(4), new Boolean(false)},
         {"Willie", "Walker", "Phthalo Blue", new Integer(4), new Boolean(false)},
         {"Kathy", "Walrath", "Blue", new Integer(8), new Boolean(false)},
         {"Arnaud", "Weber", "Green", new Integer(44), new Boolean(false)}
    // Create a model of the data.
    TableModel dataModel = new AbstractTableModel() {
    // These methods always need to be implemented.
    public int getColumnCount() { return names.length; }
    public int getRowCount() { return data.length;}
    public Object getValueAt(int row, int col) {return data[row][col];}
    // The default implementations of these methods in
    // AbstractTableModel would work, but we can refine them.
    public String getColumnName(int column) {return names[column];}
    public Class getColumnClass(int col) {return getValueAt(0,col).getClass();}
    public boolean isCellEditable(int row, int col) {return (col==4);}
    public void setValueAt(Object aValue, int row, int column) {
    data[row][column] = aValue;
    };

  • Selecting fields  PLD  from another form

    Hi Experts,
                    I want to print invoices which are in four format like sometimes i am using GRN no which is not in invoice form of SAP -B1  if i want to select fileds in PLD from another form Lets say right now if i have open A/P invoice and some fields is in another for Lets Say Item master data so can i select that feld  in PLD
                        Pls revert back that this can be done or not or even if  i am not clear enugh
    thankx and regard
    Satish tale ( SAP-B1 functional consultant ,Paradyne Infotech limited)

    Effectively, you can copy a field from a form to an other in order to add tables.
    Sincerely,
    Olivier SPINELLI

  • Invoke a from from another form

    Hi,
    Is it possible to invoke a form from another form. For example, based on a radio button choice or in button click event, i just need to show another form, but not in seperate window. We tried using app.launchURL(form workspace url). However it doesnt work in desired way.
    Please help if you have any idea on this.
    Regards,
    Sudha

    Sudha....
    the technical aspect you want to prove is calling another webpage...
    What is at the end of the webpage is irrelevant....
    your test code is:
      xfa.host.gotoURL(www.google.co.za);
    you work code is:
    xfa.host.gotoURL(http://someserver/pdfs/mypdf.pdf);
    have fun...
    8 BIT PLATOON
    design develop deploy
    www.8bitplatoon.com

  • How do you call a method from  another class without extending as a parent?

    How do you call a method from another class without extending it as a parent? Is this possible?

    Why don't you just create an instance of the class?
    Car c = new Car();
    c.drive("fast");The drive method is in the car class, but as long as the method is public, you can use it anywhere.
    Is that what you were asking or am I totally misunderstanding your question?
    Jen

  • How to call a method from another class

    I have a problem were i have to call a method from another class. What is the command line that i have to use. Thanks.

    Here's one I wipped up in 10 minutes... Cool!
    package forums;
    import javax.swing.JFrame;
    import javax.swing.JTextArea;
    import krc.utilz.io.Filez;
    import java.io.FileNotFoundException;
    class FileDisplayer extends JFrame
      private static final long serialVersionUID = 0L;
      FileDisplayer(String filename) {
        super(filename);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(600, 800);
        JTextArea text = new JTextArea();
        try {
          text.setText(Filez.read(filename));
        } catch (FileNotFoundException e) {
          text.setText(e.toString());
        this.add(text);
      public static void main(String args[]) {
        final String filename = (args.length>0 ? args[0] : "C:/Java/home/src/forums/FileDisplayer.java");
        try {
          java.awt.EventQueue.invokeLater(
            new Runnable() {
              public void run() {
                new FileDisplayer(filename).setVisible(true);
        } catch (Exception e) {
          e.printStackTrace();
    Filez.read
       * reads the given file into one big string
       * @param String filename - the name of the file to read
       * @return the contents filename
      public static String read(String filename) throws FileNotFoundException {
        return Filez.read(new FileReader(filename));
       * Reads the contents of the given reader into one big string, and closes the reader.
       * @param java.io.Reader reader - a subclass of Reader to read from.
       * @return the whole contents of the given reader.
      public static String read(Reader in) {
        try {
          StringBuffer out = new StringBuffer();
          try {
            char[] bfr = new char[BFRSIZE];
            int n = 0;
            while( (n=in.read(bfr,0,BFRSIZE)) > 0 ) {
              out.append(bfr,0,n);
          } finally {
            if(in!=null)in.close();
          return out.toString();
        } catch (IOException e) {
          throw new RuntimeIOException(e.getMessage(), e);
      }Edited by: corlettk on Dec 16, 2007 1:01 PM - dang [code [/tags][                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to capture an entry and use it in another form??

    i have a login form i wana capture the user type and use it in another form,
    how to do that?!?

    Hello,
    There are several ways to pass arguments from form to form.
    You can use global variables that you can write:
       :GLOBAL.my_global_variable := 'Hello' ;Then you can read in the another form
       the_value := GLOBAL.my_global_variable ;You can also use Forms parameters
    see the onlin documentation about global variables and parameters.
    Francois

  • Query a second form from another form by passing value

    Hi,
    I have two forms. I am trying to query a second form from another form. I have managed to display the query results in the second form by passing value from the first form. I did it according to the details in the Oracle 9ias Portal Technical FAQ html file.
    It works fine when there is already a row in the first form. When I insert a new row in the first form and query the second form which has key from the first form, there is no matching rows displayed which is correct but detail action mode is 'NONE' for all detail rows.
    According to the FAQ, it says the following:-
    "When the called form is started, it executes a query with the supplied condition (in this case, "where deptno=10"). If the query is successful, the matching rows are displayed in Update mode. If no matching rows are found, the form starts in Insert mode."
    It does not happen for me. I get NONE mode for no matching rows. Is this a BUG ? I am working on Portal version 3.0.9.8.0.
    Is there something wrong in the code I wrote ? I would like to have all the detail mode as Insert.
    Here is the following code I wrote on SUCCESSFUL SUBMISSION OF THE FORM.
    declare
    my_url varchar2(1000);
    v_deptno number;
    begin
    v_deptno := p_session.get_value_as_NUMBER(p_block_name => 'DEFAULT', p_attribute_name => 'A_DEPTNO');
    my_url := 'PORTAL30.wwa_app_module.link?p_arg_names=_moduleid&p_arg_values=1268491962&p_arg_names=_show_header&p_arg_values=YES&p_arg_names=deptno&p_arg_values='||LTRIM(TO_CHAR(v_deptno))||'&p_arg_names=_deptno_cond&p_arg_values=%3D';
    go(my_url);
    end;

    Hi,
    The behaviour is OK as in the MD form there are two states "Save" and "Query and Save" and when the form is in "Query and Save" mode that means you can use it for both Query aswell as Save which is decided by your "Master action" if that is None it is used for Query , for Insert you will have to select Insert ,this is the Insert Mode behavior.
    If you open a new MD form that is also in the "Query and Save" the same behaviour will be there.
    Hope this answers your query.
    rahul

  • Calling a method from another file

    This is pretty basic stuff but i can't seem to get it right. I am calling a method from another file. The other file IS located in the same folder BUT when i compile i get errors
    "cannot find symbol" <===referring to limit and sieve i believe.
    The method name is "sieve" the file name is "PrimeSieve2008" and "limit" is the variable in brackets in the real method.
         public static void main (String [] args) {
    final int [] PRIMES;
    int sieve = PrimeSieve2008.sieve(limit);
         PRIMES = sieve(getValidInt());
              for (int j = 0; j<PRIMES.length; j++) {
                   System.out.println("Prime[" + j + "] = " + PRIMES[j]);
    Is "int sieve = PrimeSieve2008.sieve(limit)" the wrong way to call a file?
    Thanks a million,
    Alex
    Edited by: Simplistic2099 on Apr 3, 2008 7:47 PM
    Edited by: Simplistic2099 on Apr 3, 2008 7:49 PM

    Simplistic2099 wrote:
    the other method runs fine:
    "public static int[] sieve(final int limit){
    int candidate; // possible prime
    int count; // no. of primes found
    boolean[] mayBePrime = new boolean[limit+1];
    // remaining possibilities
    final int[] PRIMES; // array to return
    // initialize mayBePrime
    for ( int j = 0 ; j <= limit ; j++ ) {
    mayBePrime[j] = true;
    mayBePrime[0] = mayBePrime[1] = false;
    // apply sieve, and count primes
    candidate = 2;
    count = 0;
    while ( candidate <= limit ) {
    if ( mayBePrime[candidate] ) {
    count++;
    for ( int j = 2 * candidate ; j <= limit ; j += candidate ) {
    mayBePrime[j] = false;
    } // end for
    } // end if
    candidate++;
    } // end while
    // fill up new array with the primes found
    PRIMES = new int[count];
    count = 0;
    for (int j = 2 ; j <= limit ; j++ ) {
    if ( mayBePrime[j] ) {
    PRIMES[count] = j;
    count++;
    } // end if
    } // for
    return PRIMES;
    } // sieve
    I really am clueless here.in this one you are passing in limit.
    in the other one you are getting limit from somewhere outside of main.

Maybe you are looking for