Passing the listBox1.SelectedItem value from one form to another?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user033088
    New Member
    • Mar 2013
    • 25

    Passing the listBox1.SelectedItem value from one form to another?

    The output for the listBox1.Select edItem in Form1 is a path (eg: "E:\\New Files")
    Now Form2 basically contains the code for an application. I want to use the output of this selectedItem in Form2.
    Please help me as I am very new to C#.
    Thank you in advance
  • vijay6
    New Member
    • Mar 2010
    • 158

    #2
    Hey user033088, inside the 'listbox1_Selec tedIndexChanged ' event write the following line,

    Code:
    Form2 Frm2 = new Form2(Convert.ToInt32(listbox1.SelectedItem));

    And inside the 'Form2' add a new constructor with one integer argument. Like as follows,

    Code:
    public Form2(int value)
    {
            MessageBox.Show(value.ToString());
            // Do your work
    }

    Comment

    Working...