I have two classes. the first class is form1 which has a combobox and three options. I've been trying to find a way to get the current combobox selectedindex from my other class but all my attempts have failed. Here's some code from my last attempt.
public partial class Form1 : Form
{
form2 herochoose = new form2();
public void comboBox1_SelectedIndexChanged_2(object sender, EventArgs e)
{
heroischosen();
}
public int heroischosen()
{
if (comboBox1.SelectedIndex == 0)
{
herochoose.HeroChoosen = 0;
}
else if (comboBox1.SelectedIndex == 1)
{
herochoose.HeroChoosen = 1;
}
else if (comboBox1.SelectedIndex == 2)
{
herochoose.HeroChoosen = 2;
}
return herochoose.HeroChoosen;
}
}
and from form 2
public partial class form2 : Form
{
private int _heroChoice;
public int HeroChoosen
{
get { return _heroChoice; }
set { _heroChoice = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
if (_heroChoice == 0)
{
Console.WriteLine("herochoice1");
}
else if (_heroChoice == 1)
{
Console.WriteLine("herochoice2");
}
else if (_heroChoice == 2)
{
Console.WriteLine("herochoice3");
}
}
}
when form1 is active it shows that each choice is properly being chosen in the combobox, but when I start form2 it never keeps the combobox choice. I'm sorry if I'm missing something really simple.
Thanks.