Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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
 
Old May 12th, 2005, 12:19 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old May 12th, 2005, 12:53 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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



 
Old May 12th, 2005, 01:55 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello

how to reference the form1 in form2. please explain.

I have already made combobox's modifier to public.

With Regards,
Raghavendra Mudugal
 
Old May 12th, 2005, 02:18 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

HI,

Thats shown in the pseudocode,

Declare callerfrm and assinging from ShowForm2 function

Prashant


 
Old May 12th, 2005, 03:52 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old May 12th, 2005, 05:20 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old May 12th, 2005, 05:50 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 221
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old May 12th, 2005, 06:12 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner Question - ComboBox Items edusem C# 2005 3 April 1st, 2007 10:10 AM
Adding Menu Items using VB SamuelP ASP.NET 2.0 Professional 0 October 23rd, 2006 08:01 AM
How to fill a combobox with the items from a query MacDevv C# 1 August 21st, 2006 07:59 AM
ComboBox Items as Variables Dim As Crazy Beginning VB 6 2 October 19th, 2004 08:02 PM
Adding items to ListBox on the client. chessgame General .NET 4 August 7th, 2004 12:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.