 |
| C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 12th, 2005, 12:19 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Adding Items to the combobox from the second form
Hello,
I have two forms (Form1 and Form2) . Form1 contains one Combobox and a button which calls the second form on on_click event. In second
form I have a textbox and a button. on click of this button i want to
add a item in the Form1's combobox.
How do i do this using c# in windows application. I am currently
using vs.net 2003.
Please Help. (hope to see code sample that really makes a lot clear)
With Regards,
Raghavendra Mudugal
__________________
With Regards,
Raghavendra Mudugal
|
|

May 12th, 2005, 12:53 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
1) Expose the combobox though a public property
2) Keep the reference of the form1 in form2
3) Now can add items to the Form1.comboboxProperty
Eg pseudocode:
Form1
-------
on_click()//loads form2
{
Form2 frm2 = new Form2();
frm2.ShowForm2(this); //custom method which shows tthe form and keeps the callers reference
}
Form2
-------
Form1 callerfrm;
ShowForm2(Form1 caller)
{
callerfrm=caller;
this.Show();
}
button_click()
{
callerfrm.comboboxProperty.items.add("Item1")
}
Hope things are clear
Prashant
|
|

May 12th, 2005, 01:55 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hello
how to reference the form1 in form2. please explain.
I have already made combobox's modifier to public.
With Regards,
Raghavendra Mudugal
|
|

May 12th, 2005, 02:18 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
HI,
Thats shown in the pseudocode,
Declare callerfrm and assinging from ShowForm2 function
Prashant
|
|

May 12th, 2005, 03:52 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
i did the way you told and the other ways also i tried.
when we say
Form1 callerFrm;
callerFrm becomes the clone of the Form1 and what ever the logic is executed
it will executes with respect to callerFrm and not with respect to Form1
I need this code to execute with the main Form1 and want to see the items
added there not in the callerFrm.
I have tried this some others way too, but they too failed.
Hope to see some solid working sample that really works.
With Regards,
Raghavendra Mudugal
|
|

May 12th, 2005, 05:20 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
How do you show this form2 ?
Somewere you will be showing it, change that call to ShowForm2 and pass the form1 as paramater.
Prashant
|
|

May 12th, 2005, 05:50 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hello
thank you so much, finally its working here.
just anothe small doubt, how to know this kind of code should be written in such cases.
many thanks
With Regards,
Raghavendra Mudugal
|
|

May 12th, 2005, 06:12 AM
|
|
Friend of Wrox
|
|
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
Learn Object Oriented concepts more, especilly how objects talk to each other
you can make it!!!!!!!!
Happy Coding
Prashant
My blog: http://prashantprof.blogspot.com
|
|
 |