Passing the listBox1.SelectedItem value from one form to another?
The output for the listBox1.SelectedItem 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
Loading
Jignesh TrivediPosted Apr 8, 2013, 11:46 PM
hi,
you can use constructor to pass value from one page to another page if you are working with windowbase application.
public Form2(int mydata)
{
// do some thing...
}
private void button1_Click(object sender, EventArgs e)
{
int data = 5;
Form2 f = new Form2(data);
f.show();
}
you can use any state Management technique like viewstate, session Query string etc if you are working on web base application
hope this will help you.
VulpesPosted Apr 8, 2013, 6:45 PM
You then need to get a reference to Form1:
Form1 f1 = (Form1)Application.OpenForms["Form1"];
string item = "";
if (f1.listBox1.SelectedIndex > -1)
{
item = f1.listBox1.SelectedItem.ToString();
}