Hey guys,
I have two forms, form1 and form2.
My form1 has a combo box and a button.
Here's form1 code.
Form1
public partial class Form1 : Form
{
bool s;
public Form1()
{
InitializeComponent();
s1 = comboBox1.Text;
}
private void Form1_Load(object sender, EventArgs e)
{
}
public string s1;
private void button1_Click(object sender, EventArgs e)
{
s = true;
Form2 oj = new Form2(s1);
oj.Show();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
public struct forms1
{
public string s;
public forms1(string s)
{
this.s = s;
}
public string text()
{
return "this was selected" + s;
}
}
Now the thing is, as you can see i have declared a structure, with the help of this structure i am trying to show, in second form, the value that was selected from combo box.
Here's code for my Form2
Form2
public partial class Form2 : Form
{
forms1 fr;
string ss1;
public Form2(string re)
{
InitializeComponent();
ss1 = re;
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
fr = new forms1(ss1);
MessageBox.Show(fr.text());
}
}
The problem here is as structure is declared outside the class in form1, i cannot declare variables for 'combobox.text' in it. And so now, when i click the button
in form2 it shows the text that was declared in struct but not the text that was selected in combo box. So is there any way to display the text of combo box.
NOTE : I know there's another way without using structure but i need to do it using structure.
Thanks and regards
ajinkya