-5

I have a form1 which contains datagridview and the button1(this form load the file which contains data on it). I then created a form2 to use it as a wizard to make it more usable.form2 contains button2 and textbox2.(button2 browse the file and textbox will populate the directory). when the user clicks button1, it will open up form2 and you browse the file and click finish button after browsing the file.

I want to the file you selected from form2 to load to be loaded on the form1. I don't have an idea on how I can do it.

was trying to do this, am just not sure how I can do. Thanks.

    private List<form2> _Listcontrols;
    private string _InputText;
    private DataGridView _Gridview;
helb
  • 7,609
  • 8
  • 36
  • 58
Khane
  • 1
  • 1
  • 5
  • 5
    http://tinyurl.com/namzjvr – Tim Schmelter Mar 26 '15 at 10:38
  • possible duplicate of [How do you pass an object from form1 to form2 and back to form1?](http://stackoverflow.com/questions/4887820/how-do-you-pass-an-object-from-form1-to-form2-and-back-to-form1) – Orace Mar 26 '15 at 11:05

1 Answers1

0

use a new class for that like this:

//project name
namespace data
{
    //class name
    static class data
    {
      //boolean     
      public static Boolean publicbool = false;
      //int      
      public static Int number = 9;
      //list
      public static List<string> printitems = new List<string>();
    }
}

and you would call it like this: data.publicbool = true; to set the bool to true.

To create a new class ,

  • go to the solution explorer
  • right click your project name
  • add
  • new item
  • class
  • give the class a name

once you done that it will look something like this

//project name
namespace data
{
    //class name
    static class data
    {

    }
}

Then you put your variables in the static class, in your case the variables would be like this.

//project name
namespace data
{
    //class name
    static class data
    {
      public static List<form2> _Listcontrols;
      public static string _InputText;
      public static DataGridView _Gridview;
    }
}

NOTE: this could be placed in the program class thats made along with the project if you simply place it above the summary, but I do not recommend that since a new class is just as simple and will allow you to give it a meaningfull name and make it more clear if you have a lot of variables

maam27
  • 444
  • 3
  • 21
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/73863/discussion-on-answer-by-maam27-how-to-pass-data-from-form1-to-form2). – Taryn Mar 26 '15 at 15:28
  • question how does one create a chat, i did see a privledge of creating a chat but im not at a point where im allowed to, so if this happens again at a later date how would i create a chat? – maam27 Mar 26 '15 at 15:46
  • Typically all users need to have the rep to chat, the OP doesn't but since I'm a moderator I'm able to move the conversation there to continue. – Taryn Mar 26 '15 at 15:47
  • thought it would have been something along those lines, i would go to a chat if i could but i gues ill have to wait a bit longer before im capable of doing that. – maam27 Mar 26 '15 at 18:02