nencor
nencor

Reputation: 1651

C# how to pass value from form to form through datagridview?

i have form, it goes like this

picture 1

that nomor tabungan is auto generate
the problem is, i want to get nomor nasabah value from different form, through the datagridview. take a look at the following picture

enter image description here

there's a button ambil to retrieve the nomor nasabah value, and pass them to nomor nasabah textbox.text

i have successfully to get the nomor_nasabah value from datagridview. it is shown like the following picture enter image description here

how do i pass the value to the tambah tabungan . nomor nasabah textbox.text ? i have set the textbox modifier into public so when i click the ambil button, the textbox is filled with the retrieved value automatically.

how do i do that ?

i did the following code, and idk why it doesn't work

here is the ambil button code

private void button2_Click(object sender, EventArgs e)
    {
        Tabungan.Tambah tambahtabungan = new Tabungan.Tambah();
        //nomornya is the retrieved value            
        tambahtabungan.textBox2.Text = nomornya;
    }

here is the cari button code, to show getCustomer form

 private void button2_Click(object sender, EventArgs e)
    {
        if (getcustomer == null || getcustomer.IsDisposed)
        {
            getcustomer = new getNasabah();                
            getcustomer.Show();
        }
    }

Upvotes: 1

Views: 820

Answers (1)

Yograj Gupta
Yograj Gupta

Reputation: 9869

You should try this.

first make a public property on getCustomer form like

public string nomornyaValue { get; set;}

and modify your ambil button click event like, and set this property to your datagrid value.

private void button2_Click(object sender, EventArgs e)
{
   nomornyaValue = nomornya;
   this.DialogResult = DialogResult.OK;
}

and on tambah tabungan button Cari click call getCustomer form like

 private void Cari_Click(object sender, EventArgs e)
 {
     /*getCustomer getCustomerForm = new getCustomer();
     if(getCustomerForm.ShowDialog() == DialogResult.OK)
     {
          textBox2.Text = getCustomerForm.nomornyaValue;
     }*/
    if (getcustomer == null || getcustomer.IsDisposed)
    {
        getcustomer = new getNasabah();                
    }
    if(getcustomer.ShowDialog() == DialogResult.OK)
    {
        textBox2.Text = getcustomer.nomornyaValue;
    }
 }

Upvotes: 2

Related Questions