title: Retrieving Selected Row/Cell Values in DataGridView From one form to another
body: <p>I am new to C#.net . I want to get the dataGridView cell click cell values to textbox of another form but couldn't found the right method. I have two forms 1. UserPanelfrm and 2. frmAddProjects . UserPanelFrm consists of dataGridView which shows the list of projects from database . I want to show the cell information of the doubled clicked cell to be shown in textboxes of frmAddProjects.</p>
  
  <p>Codes for ProjectClass.cs</p>
  
  <pre><code>public class ProjectClass
  {
      SqlConnection conn = new SqlConnection(DataConnectionClass.DbConnection);
      public int ManageProject(int ProjectID, String BusinessName, String ContactPerson, String Phone, String Address, String CreatedDate, String AssignedTo, String Mode)
      {
          try
          {
              int result = 0;
              SqlCommand cmd = new SqlCommand("sp_ManageProject", conn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@ProjectID", ProjectID);
              cmd.Parameters.AddWithValue("@BusinessName", BusinessName);
              cmd.Parameters.AddWithValue("@ContactPerson", ContactPerson);
              cmd.Parameters.AddWithValue("@Phone", Phone);
              cmd.Parameters.AddWithValue("@Address", Address);
              cmd.Parameters.AddWithValue("@CreatedDate", CreatedDate);
              cmd.Parameters.AddWithValue("@AssignedTo", AssignedTo);
              cmd.Parameters.AddWithValue("@Mode", Mode);
              conn.Open();
              result = cmd.ExecuteNonQuery();
              conn.Close();
              return result;
          }
          catch (Exception ex)
          {
  
              throw ex;
          }
  
           }
      public DataTable SelectAllProjects()
      {
          try
          {
              SqlCommand cmd = new SqlCommand("Select ID,ProjectID,BusinessName,ContactPerson,Phone,Address,CreatedDate,AssignedTo from tbl_ProjectInformation", conn);
              DataTable dt = new DataTable();
              conn.Open();
              SqlDataReader dr = cmd.ExecuteReader();
              dt.Load(dr);
              conn.Close();
              return dt;
          }
          catch (Exception ex)
          {
  
              throw ex;
          }
      }
  }
  </code></pre>
  
  <p>Code to call ProjectList to UserPanelfrm dgvProjectDetails:</p>
  
  <pre><code>ProjectClass pc = new ProjectClass();
  dgvProjectDetails.DataSource = pc.SelectAllProjects();
  </code></pre>
  
  <p>Code for cellclick</p>
  
  <pre><code>    private void dgvProjectDetails_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
  
  DataGridViewCell cell = null;
          foreach (DataGridViewCell selectedCell in dgvProjectDetails.SelectedCells)
          {
              cell = selectedCell;
              break;
          }
          if (cell != null)
          {
              DataGridViewRow row = cell.OwningRow;
              frmAddProjects.projectid = row.Cells["ProjectID"].Value.ToString();
              frmAddProjects.businessname = row.Cells["BusinessName"].Value.ToString();
              frmAddProjects.contactperson = row.Cells["ContactPerson"].Value.ToString();
              frmAddProjects.phone = row.Cells["Phone"].Value.ToString();
              frmAddProjects.address = row.Cells["Address"].Value.ToString();
              frmAddProjects.createddate = row.Cells["CreatedDate"].Value.ToString();
              frmAddProjects.assignedto= row.Cells["AssignedTo"].Value.ToString();
              // etc.
              frmAddProjects ProjectDetail = new frmAddProjects();
              ProjectDetail.ShowDialog();
          }
  }
  </code></pre>
  
  <p>frmAddProjects code: </p>
  
  <pre><code>public static string projectid, businessname,contactperson,phone,address,createddate,assignedto;
       public frmAddProjects()
      {
          InitializeComponent();
  
      }
  
  public void fillRecord()
      {
          txtProjectID.Text = projectid;
          txtBusinessName.Text = businessname;
          txtContactPerson.Text = contactperson;
          txtPhone.Text = phone;
          txtAddress.Text = address;
          dTPCreatedDate.Text = createddate;
          cmbAssignedTo.Text = assignedto;
      }
  </code></pre>