I am trying to take the value of a cell from a selected row in my form 1 datagridview. I want to store this value in a variable so I can update specific entries my database with the appropriate ID using said variable.
I have already set the datagridview to public in properties but for some reason it still wont recognize the datagrid on my other form. My code looks like this on Form 2:
var selectedAppointmentId = appointmentDgv.CurrentRow.Cells[0].Value;
Appointment appointment = new Appointment();
appointment.AppointmentID = int.Parse((string)selectedAppointmentId);
This code is located in an edit button so that I might make changes to the database. I keep getting the error: "The name 'appointmentDgv' does not exist in current context". I am relatively new to C#.