1
Hello, I know it’s a stupid question, but I’m having a hard time accessing a variable from another class. Situation: - I’m using a datagrid, which I want to take the value of one 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 this value. But when I try to access the value of another class I can’t.
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 shows Messagebox with a value at zero. I’ve tried this many ways, but I couldn’t make it work.
Situation:
I’m trying to set up a simple customer registration schedule with phone name address these things. In Form2 is the screen where you have a Datagrid, with the information, of the database. I am trying to create a button, to change the customer data, I click on the record I want, when clicking is taken the registration ID, click on the change button and open the Form1 already in the record that was selected in Form2.
Since thanks.
Why do you turn something into
string
and then inint
?– Maniero
I’m kind of Noob, I kind of got the script on the net. If I take the Tostring, will it be full ovalor? or will it be as an object?
– gabriel oliveira