How to Transferring objects between windows forms in c#

后端 未结 4 2039
暖寄归人
暖寄归人 2021-01-29 06:37

i got a ListView in the windows form.When form loads ListView loading with personel objects. I want to do when some user double clicks on ListView , gets the personel object fro

4条回答
  •  Happy的楠姐
    2021-01-29 07:02

    In the new form that will be opened, add a new property in the form class;

    private PERSONNEL Personnel{get; set;}
    public ShowPersonnel(PERSONNEL _personnel){
       this.Personnel = _personnel;
       //do whatever you want here
    }
    

    In the main form;

    private void listView1_SelectedIndexChanged(object sender, EventArgs e){
            PERSONNEL personnel = listView1.SelectedItems[0].Tag as PERSONNEL;
            Form2 form2 = new Form2();
            form2.ShowPersonnel(personnel);
            form2.Show();
    
    }
    

    May include typos. Change PERSONNEL to PERSONEL.

提交回复
热议问题