Hello I have datagridview in form1 and through form1 I open form2 and through form2 I open form3 and string named vyber_ID_K
placed in Form1 needs to be accessed in Form3 (I need to get its value in Form3)
this is placed on button click in form1
form2 a = new form2 ("Novy");
string vyber_IDK = (string)dataGridView1.CurrentRow.Cells["ID_K"].Value.ToString();
a.vyber_ID_K = vyber_IDK;
a.Show();
a.Closed += klient_Closed;
I would like to access vyber_ID_K in form 3
, how it can be done? I tried to set public string vyber_ID_K in form2 and pass it similary to form3 but I get null
. Am I doing it right? Is there any other better solution please?
Thanks in advance.
My step-by-step according to Servy:
button click in Form 1
Func vyberIDKGetter = () => dataGridView1.CurrentRow.Cells["ID_K"].Value.ToString();
try { form2 = new form2 ("Novy"); a.vyberIDKGetter = () => dataGridView1.CurrentRow.Cells["ID_K"].Value.ToString(); a.Show();
}
button click in form2
public Func vyberIDKGetter; private void button1_Click(object sender, EventArgs e) { nova_platba b = new nova_platba("novy"); b.vyberIDKGetter(); b.Show(); b.Closed += klient_Closed; }
In form3
Func<string> vyberIDKGetter = veberIDK; string vyberIDK = vyberIDKGetter(); SqlCommand sc = new SqlCommand(@" INSERT INTO kliplat (datum,text,castka,akce,subkey,priznak,rocnik) VALUES (@datum,@text,@castka,@akce,@subkey,@priznak,@rocnik); SELECT scope_identity(); ", spojeni); sc.Parameters.AddWithValue("@subkey", vyberIDK);