I got windows form am trying to pass value from that form to new one, when an button is clicked. using:
private void Edit_button_Click(object sender, EventArgs e)
{
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
Edit item = new Edit(int.Parse(listBox1.SelectedIndex.ToString()));
item.ShowDialog();
}
}
When I run the program it doesn't show the form I designed it shows this instead
But when i change the code to this:
Edit item = new Edit();
item.ShowDialog();
run it, it display the right thing, but doesn't pass a value to the second form.
I there a way to pass a value to another form?
Add a property
Edit item = new Edit();
item.Value = 5;
item.ShowDialog();
You have to define this property to use it. Extend your Edit
class like that:
class Edit {
...
public int Value { get; set; }
...
}
Just a guess: In your own Constructor you forgot to call IntializeComponents().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With