Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi

This is Tarun.

I want to copy data from one user control to another after clicking select button.

When ever we click on Dark triangle button in User control 1 then it displays user

control 2 and when ever we select the row in a Datagridview and select select button

then it displays corresponding column values in the textboxes in the 1st user control.

I have written this code.But no use.

In User Control 2 in select button:name is Employeesearch.cs

public void btn_Select_Click(object sender, EventArgs e)
{
DataGridViewRow dr = DGV_Summary.SelectedRows[0];
DGV_Summary.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
Work wrk = new Work();
wrk.EId1 = Convert.ToInt32(dr.Cells[0].Value.ToString());
wrk.EName1 = dr.Cells[1].Value.ToString();
wrk.Paygrade1= dr.Cells[2].Value.ToString();
wrk.PayPeriod1= dr.Cells[3].Value.ToString();
wrk.LoadData();
this.ParentForm.Close();


}
In User Control 1 In Loaddata method:Name is Work.cs

C#
namespace WorkExperience
{
    public partial class Work : UserControl
    {
        private int EmpId;

        public int EId1
        {
            get { return EmpId; }
            set { EmpId = value; }
        }
        private string EName;

        public string EName1
        {
            get { return EName; }
            set { EName = value; }
        }
        private string Paygrade;

        public string Paygrade1
        {
            get { return Paygrade; }
            set { Paygrade = value; }
        }
        private string Payperiod;

        public string PayPeriod1
        {
            get { return Payperiod; }
            set { Payperiod = value; }
        }
        public Work()
        {
            InitializeComponent();
        }
        public  void LoadData()
        {

            Txt_EmpCode.Text = Convert.ToString(EId1);
            Txt_EmpName.Text = EName;
            Txt_Pay.Text = Paygrade;
            ddl_PayPeriod.SelectedItem = Payperiod;

        }
Posted

1 solution

What is the problem you have?

is it that is does selecet the row that you have clicked on?

if so try this,

DGV_Summary.SelectionMode = DataGridViewSelectionMode.SelectedRows;
 
Share this answer
 
Comments
TarunKumarSusarapu 14-Jul-14 5:55am    
I have taken two user controls named as work and empsearch.

When user wants to click Collapsed button in work form then it will display empsearch form with datagridview data.

In Empsearch form I have taken select button.After selecting a row in datagridview then click on select button.Then it displays work form with all the selecting row columns in the textboxes.

For that I have written above code.Kindly see this code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900