title: Passing object from one windows form to another
body: <p>I have two windows forms in my application. First one is Main form and the second one is lookup form. I'm trying to open lookup form from the main form in a text box key leave event and then I'm opening the lookup form. My lookup form has a data grid view and I' loading it in the form load event of the lookup form. I'm reading my selected value on the grid view of the lookup window to an object. I want to close the lookup window as soon as I read the values of the selected row to the object and I want to pass it to the main form? How can I do that?
  This is what I have done.
  In the main form.</p>
  
  <pre><code>        LookupModelType="";
          if (e.KeyCode.Equals(Keys.F3))
          {
              foreach (Form frm in Application.OpenForms)
              {
                  if (frm is FormControllers.Lookup)
                  {
                      if (frm.WindowState == FormWindowState.Minimized)
                      {
                          frm.WindowState = FormWindowState.Normal;
                          frm.Focus();
                          return;
                      }
                  }
              }
                  LookupModelType = "Product";
                  FormControllers.Lookup newLookUp = new FormControllers.Lookup(LookupModelType);                
                  newLookUp.ShowDialog(this);
          }
  </code></pre>
  
  <p>In the lookup window </p>
  
  <pre><code>  private string GridType = "";
          public Lookup(String  LookupModelType)
          {
              InitializeComponent();
              this.GridType = LookupModelType; 
          }
  
          private void Lookup_Load(object sender, EventArgs e)
          {
              if (GridType == "Product")
              {
                  using(DataControllers.RIT_Allocation_Entities RAEntity  = new DataControllers.RIT_Allocation_Entities())
                  {
                      dgvLookup.DataSource = RAEntity.TBLM_PRODUCT.ToList&lt;DataControllers.TBLM_PRODUCT&gt;();
                  }  
              }
              dgvLookup.ReadOnly = true;
          }
  
          private void dgvLookup_CellClick(object sender, DataGridViewCellEventArgs e)
          {
              if (e.RowIndex &lt; 0)
              {
                  return;
              }
              int index = e.RowIndex;
              dgvLookup.Rows[index].Selected = true;
          }
  </code></pre>