Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Passing a value a new form

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 problem

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. enter image description here

I there a way to pass a value to another form?

like image 998
UnknownUser Avatar asked May 03 '12 10:05

UnknownUser


2 Answers

Add a property

Edit item = new Edit();
item.Value = 5;
item.ShowDialog();

EDIT:

You have to define this property to use it. Extend your Edit class like that:

class Edit {
    ...
    public int Value { get; set; }
    ...
}
like image 130
juergen d Avatar answered Oct 06 '22 00:10

juergen d


Just a guess: In your own Constructor you forgot to call IntializeComponents().

like image 26
yan.kun Avatar answered Oct 05 '22 23:10

yan.kun