Hello, I know it's a beast question, but I'm having trouble accessing a variable from another class. Situation: - I am using a datagrid, which I want to get the value of a column, and transport that value to another class.
Script:
public partial class Form2 : Form
{
public string idString;
public int idselecionada;
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
idString = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
idselecionada = Int32.Parse(idString);
MessageBox.Show("ID " + idselecionada);
}
This script works perfectly. I click on the line it takes the value of the first column, and shows me that value. But when I try to access the value of another class I can not.
public partial class Form1 : Form
{
private int idinicial;
Form2 varivavel2 = new Form2();
private void Form1_Load(object sender, EventArgs e)
{
idinicial = varivavel2.idselecionada;
MessageBox.Show("ID Inicial " + idinicial);
}
The problem is that when I open Form 1, it appears Messagebox with a value of zero. I've tried this in several ways, but I could not get it to work.
Location:
I'm trying to put together a simple customer registration schedule, with phone address address these things. In Form2 is the screen where you have a Datagrid, with the information, of the database. I'm trying to create a button, to change the client data, I click on the record I want, when I click it it gets the registry ID, I click the change button and it opens Form1 already in the record that was selected in Form2. >
Thank you.