H
H
HappyCougar2015-04-11 01:57:58
C++ / C#
HappyCougar, 2015-04-11 01:57:58

How to make a request to an object of another form?

In the first form, I open the second one like this:

addgroup form = new addgroup();
form.Owner = this;
form.ShowDialog();

I'm trying to access the object of the first from the second one:
public void button1_Click(object sender, EventArgs e)
        {
            int val_id = this.Owner.dataGridView1.Rows.Count + 1;
        }

But it doesn't work, right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir S, 2015-04-11
@hePPer

make a new constructor in the addgroup form that will take dataGridView as an input and store it as a field.
when creating, pass your grid to a new form and use
private DataGridView maingrid there;
public addgroup(DataGridView grid)
{
maingrid=grid;
}
addgroup form = new addgroup(dataGridView1);
form.Owner = this;
form.ShowDialog();
public void button1_Click(object sender, EventArgs e)
{
int val_id = maingrid.Rows.Count + 1;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question