Hi,
I am stuck with one problem at passing combobox value from one FORM1 to FORM2.
I wrote code in form2 like this:
Form1 frm1= new Form1();
frm1.combobox1.SelectedItem;
I am getting null value.
How can I pass values?
Thanks,
Darma
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Feb 12, 2013, 10:38 PM
hi,
If you open form2 from the form1 then you may pass combo value in constructior of form2
like....
public Form2(string value)
{
}
private void callingFunction()
{
Form2 obj = new Form2(passcomboselected value);
}
hope this will help you.
Gopal MahadakPosted Feb 16, 2013, 11:26 PM
public static string str;
then In first form take combox & load items in it..
& combox selectedValueChanged event write follwing code:
Class1.str = comboBox1.SelectedItem.ToString();
& to show form2 on button write code in form1...
Then in form2 load event:
comboBox1.Items.Add(WindowsFormsApplication1.Class1.str);
If not get check attachment
darma tejaPosted Feb 13, 2013, 3:57 AM
I am getting null error.
Anyway thanks allot.
It is working now with Jignesh Idea.
Darma
VulpesPosted Feb 12, 2013, 12:53 PM
If it is null, then are you sure that there is currently a selected item in the combobox?
darma tejaPosted Feb 12, 2013, 11:59 AM
After changing modifier to "Public" also, it is not working.
Thanks
Darma
VulpesPosted Feb 12, 2013, 11:48 AM
darma tejaPosted Feb 12, 2013, 11:43 AM
you are right. It applies in 2nd point.
The combobox hasn't been placed directly on the form but is inside some container such as a panel or groupbox.
Actually it is in TAB and groupbox.
But I changed those two controls modifiers as "public"
Thanks,
Darma
VulpesPosted Feb 12, 2013, 11:36 AM
1. The exact name of the combobox isn't comboBox1; or
2. The combobox hasn't been placed directly on the form but is inside some container such as a panel or groupbox.
Does either of these ring a bell?
darma tejaPosted Feb 12, 2013, 11:12 AM
Thanks for the reply.
I am getting error at: ComboBox cb1 = (ComboBox)frm1.Controls["comboBox1"];
this is the error: Object reference not set to an instance of an object.
Thanks,
Darma
VulpesPosted Feb 12, 2013, 11:03 AM