In button1_Click you create a new instance of the fmHome class. This is an instance of another of the fmHome instance that created it, so it does not have a highlighted line in dgCases . Calling GetCaseID() on this instance will not return what you expect.
Your button1_Click handler should have a way to call GetCaseID() in the form that opens. A very simple way is to add such a property to Form2 :
public fmHome fmHomeParent { get; set; }
Then, when you open your instance of Form2 , do the following:
private void btnEvLvlUserSelect_Click(object sender, EventArgs e) { Form2 form2= new Form2(); form2.fmHomeParent = this; form2.ShowDialog(); }
So, in your button1_Click handler button1_Click you can access this instance instead of creating a new one:
private void button1_Click(object sender, EventArgs e) {
Hope this helps!
Donut source share