redspider
March 14th, 2007, 03:49 AM
I'm new to c#.
I have the main form(Form1) with a button witch spawns another form(Form2) so the user can select a profile to open via a combo box, How do i pass that information back to the main form.
darwen
March 14th, 2007, 04:02 AM
You usually have a property on your second form which is set before it closes - the same way as OpenFileDialog has the FileName property.
i.e.
public class MainForm
{
private void button1_Click(...)
{
SubForm form = new SubForm();
if (form.ShowDialog() == DialogResult.OK)
{
int selectedItem = form.SelectedItem;
}
}
}
public class SubForm
{
private int _selectedItem;
public int SelectedItem
{
get
{
return _selectedItem;
}
}
// let's assume this form contains a list box called 'listBox1'
void listBox1_SelectedIndexChanged(...)
{
_selectedItem = listBox1.SelectedIndex;
}
}
Get it ?
Darwen.
redspider
March 14th, 2007, 05:03 AM
Thank you :)