本文介绍了单击DataGridView和按钮中的选择行后,如何将数据从一个用户控件复制到另一个用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





这是Tarun。



我想将数据从一个用户控件复制到另一个点击选择按钮后。



当我们点击用户控件1中的暗三角按钮时,它会显示用户



控制2当我们选择Datagridview中的行并选择选择按钮



然后它在第一个用户控件的文本框中显示相应的列值。



我写了这段代码。但没用。



用户控件2中的选择按钮:name是Employeesearch.cs



public void btn_Select_Click(object sender,EventArgs e)

{

DataGridViewRow dr = DGV_Summary.SelectedRows [0];

DGV_Summary.SelectionMode = DataGridViewSelectionMode.FullRowSelect;

工作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();





}

用户控制1在Loaddata中方法:名称是Work.cs



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

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;

        }

推荐答案


这篇关于单击DataGridView和按钮中的选择行后,如何将数据从一个用户控件复制到另一个用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 03:47