2015-08-23 60 views
0

我跟我的C#Windows aplication的工作,在一個名爲「病人」等命名爲「patientsDuplicatedName」,其含有的DataGridView和加載所有重複的患者姓名申請表(這和工作正常,, ) ,但我想,當slsected行得到的所有值轉換成表格「患者」在運行時(打開),而無需創建新形式的「病人」 .. 下面是我指的是代碼:如何datagridview的值傳遞給另一種形式

public partial class frmPatientsNameDuplicated : Form 
{ 
    PatientFiles frmPatientsFiles =new PatientFiles() ; 
    public frmPatientsNameDuplicated() 
    { 
     InitializeComponent(); 
    } 


    private void btnCancel_Click(object sender, EventArgs e) 
    { 
     this.Close(); 
    } 

    private void btnOk_Click(object sender, EventArgs e) 
    { 

     frmPatientsFiles.txtFileNum.Text = this.dgvPatientsName.CurrentRow.Cells[0].Value.ToString(); 
     frmPatientsFiles.txtArbName.Text = this.dgvPatientsName.CurrentRow.Cells[1].Value.ToString(); 
     frmPatientsFiles.txtEngName.Text = this.dgvPatientsName.CurrentRow.Cells[2].Value.ToString(); 
     //frmPatientsFiles.show();//this line is creating new form and run 
     this.Close(); 

    } 
} 

對不起關於提前我的英語不好&感謝

+0

你真正需要什麼?你有兩種形式form1和form2。在form2中,你加載了所有重複的患者姓名。當從form2中選擇一行時,該行的所有細節都應該傳遞給form1。 – Arshad

回答

0

我發現同樣的問題在這裏: Pass data to a existing form 所以我的代碼變得

public partial class frmPatientsNameDuplicated : Form 
{ 
PatientFiles frmPatientsFiles = Application.OpenForms["PatientFiles"] as PatientFiles; 
public frmPatientsNameDuplicated() 
{ 
    InitializeComponent(); 
} 
private void btnCancel_Click(object sender, EventArgs e) 
{ 
    this.Close(); 
} 

private void btnOk_Click(object sender, EventArgs e) 
{ 
    frmPatientsFiles.txtFileNum.Text = this.dgvPatientsName.CurrentRow.Cells[0].Value.ToString(); 
    frmPatientsFiles.txtArbName.Text = this.dgvPatientsName.CurrentRow.Cells[1].Value.ToString(); 
    frmPatientsFiles.txtEngName.Text = this.dgvPatientsName.CurrentRow.Cells[2].Value.ToString(); 
    this.Close(); 
} 
} 
0

ŧ他註釋掉線frmPatientsFiles.show()有一個評論,說該行正在創造一種新的形式。不是這樣。這只不過是顯示已上線以前創建PatientFiles frmPatientsFiles = new PatientFiles();這似乎是創建一個你不希望新的形式的形式。如果您已經有一個想要更新的現有表單,請從您的btnOk_Click事件處理程序中引用該表單。爲此,您可能希望通過構造函數或其他方法/屬性將(現有)表單的引用傳遞給您的類。我希望我能正確理解你的問題。

相關問題