private void ResetProperty_Click(object sender, EventArgs e)
 {
     Agent_sproperty_agent.Clear();
     Agent_sproperty_ID.Clear();
     Agent_sproperty_custIDFN.Clear();
     Agent_sproperty_type.ResetText();
     Agent_sproperty_livarea.Clear();
     Agent_sproperty_be.ResetText();
     Agent_sproperty_ba.ResetText();
     Agent_sproperty_year.Clear();
     Agent_sproperty_loc.Clear();
     Agent_sproperty_price.Clear();
     issold.Checked = false;
     datesold.Clear();
     propsearchdatagrid.Rows.Clear();
 }
        private void propsearchdatagridcell(object sender, DataGridViewCellEventArgs e)
        {
            /////////////////just to clean the form
            Agent_sproperty_agent.Clear();
            Agent_sproperty_ID.Clear();
            Agent_sproperty_custIDFN.Clear();
            Agent_sproperty_type.ResetText();
            Agent_sproperty_livarea.Clear();
            Agent_sproperty_be.ResetText();
            Agent_sproperty_ba.ResetText();
            Agent_sproperty_year.Clear();
            Agent_sproperty_loc.Clear();
            Agent_sproperty_price.Clear();
            issold.Checked = false;
            datesold.Clear();
            /////////////// end of clean form
            ///start populating here
            try
            {
                if (e.RowIndex >= 0)
                {
                    Agent_sproperty_ID.Text = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyID"].Value.ToString();

                    string custidfn = "ID: " + propsearchdatagrid.Rows[e.RowIndex].Cells["outputcustomerID"].Value.ToString() + " Name: "
                                      + propsearchdatagrid.Rows[e.RowIndex].Cells["CustomerFN"].Value.ToString() + " "
                                      + propsearchdatagrid.Rows[e.RowIndex].Cells["CustomerLN"].Value.ToString();

                    Agent_sproperty_custIDFN.Text = custidfn;

                    Agent_sproperty_type.Text    = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyType"].Value.ToString();
                    Agent_sproperty_livarea.Text = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyArea"].Value.ToString();
                    Agent_sproperty_be.Text      = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyBedrooms"].Value.ToString();
                    Agent_sproperty_ba.Text      = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyBathrooms"].Value.ToString();
                    Agent_sproperty_year.Text    = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyYear"].Value.ToString();
                    Agent_sproperty_loc.Text     = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyLocation"].Value.ToString();
                    Agent_sproperty_price.Text   = propsearchdatagrid.Rows[e.RowIndex].Cells["PropertyPrice"].Value.ToString();

                    string agentidfirstlastname = "ID: " + propsearchdatagrid.Rows[e.RowIndex].Cells["outputAgentID"].Value.ToString() + " Name: "
                                                  + propsearchdatagrid.Rows[e.RowIndex].Cells["AgentFN"].Value.ToString() + " "
                                                  + propsearchdatagrid.Rows[e.RowIndex].Cells["AgentLN"].Value.ToString();
                    Agent_sproperty_agent.Text = agentidfirstlastname;
                    // end of populating

                    //start filling sold status and date

                    if (String.IsNullOrEmpty(propsearchdatagrid.Rows[e.RowIndex].Cells["TransactionID"].Value.ToString()))
                    {
                        issold.Checked = false;
                        datesold.Clear();
                    }
                    else
                    {
                        issold.Checked = true;

                        string query = "select Trans_date from Transaction where Transaction_ID = \"" + propsearchdatagrid.Rows[e.RowIndex].Cells["TransactionID"].Value.ToString() + "\"";

                        try
                        {
                            connection.Open();
                            MySqlCommand     cmd  = new MySqlCommand(query, connection);
                            MySqlDataAdapter mcmd = new MySqlDataAdapter();
                            MySqlDataReader  reader;
                            mcmd.SelectCommand = cmd;

                            reader = cmd.ExecuteReader();

                            if (reader.Read())
                            {
                                datesold.Text = ((DateTime)reader["Trans_date"]).ToString("d");
                            }
                        }
                        catch
                        {
                            MessageBox.Show("Error Occured!");
                        }
                        connection.Close();
                    }
                }
            }
            catch
            {
            }
            //end of filling sold status and date
        }