双击dataGridView一行数据,打开一个另一个窗体,并把双击行的数据展示出来

本文是以list为数据源,双击获取一个list实例,并把这个实例传到另一个窗体,并把所得实例的数据展示出来。

//  frmEmployeeList.cs

//dataGridView1双击事件CellDoubleClick

  private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)

        {
              frmSave f3 = new frmSave();  
              var visit = this.dataGridView1.CurrentRow.DataBoundItem as EmployeeList;//visit  相当于一个实体
              f3.DataEntity = visit;
              f3.Show();    
        }  

//frmSave.cs

List<EmployeeList> emp=new List<EmployeeList>();

 public EmployeeList DataEntity
        {
            get
            {
                return this.m_DataEntity;
            }
            set
            {
                if (value == null)
                    return;
                    this.m_DataEntity = value;
                    this.DisplayData();     
            }
        }
        EmployeeList m_DataEntity;

public void DisplayData()

{

this.btId.text=this.m_DataEntity.empid;

this.btAge.text=this.m_DataEntity.empage;

this.btname.text=this.m_DataEntity.empname;

}

//EmployeeList.cs

public class Employee

{

public string empid;

public in empage;

public string empname;

}

原文地址:https://www.cnblogs.com/wwwlzp/p/13207872.html