Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:19:09+00:00 2026-05-26T20:19:09+00:00

I have a main windows form (MainForm.cs) where I created an instance of Customer

  • 0

I have a main windows form (MainForm.cs) where I created an instance of Customer cust.

Here is a snippet of said code:

private Customer cust;

public MainForm()
{
    InitializeComponent();
}

private void buttonDeposit_Click(object sender, EventArgs e)
{
    DepositDialog dlg = new DepositDialog();

    dlg.ShowDialog();
}

Here is the code for the Customer class. As you can see, it creates a list of BankAccounts:

class Customer
{
    private BankAccountCollection accounts;

    public Customer(BankAccountCollection accounts, TransactionCollection transactionHistory)
    {
        accounts.Add(new SavingsAccount(true,200));
        accounts.Add(new SavingsAccount(true, 1000));
        accounts.Add(new LineOfCreditAccount(true, 0));
    }

    public BankAccountCollection Accounts
    { get { return accounts; }}
}

Now, I have another form called DepositDialog, which has a comboBox within it.

How would I:

1) pass the data BankAccountCollection accounts

2) populate that comboBox with the members of that BankAccountCollection

3) display that collection as items within the list?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:19:09+00:00Added an answer on May 26, 2026 at 8:19 pm

    1) pass the data BankAccountCollection accounts

    There’s actually 5 ways to pass the data.

    1- (Not recommended if there’s too many parameters) Passing data through the constructor.

     private void ShowForm(int a, string b, double c)
    {
        Form2 frm = new Form2(a, b, c);
        frm.ShowDialog();
    }
    

    2- Using public fields of target class. (NOT RECOMMENDED AT ALL)

     private void ShowForm(int a, string b, double c)
    {
        Form2 frm = new Form2();
        frm.intval = a;
        frm.strval = b;
        frm.doubleval = c;
        frm.ShowDialog();
    } 
    

    3- Using properties.

     private void ShowForm(int a, string b, double c)
    {
        Form2 frm = new Form2();
        frm.IntValue = a;
        frm.StringValue = b;
        frm.DoubleValue = c;
        frm.ShowDialog();
    } 
    

    4- Using tags.

    private void ShowForm(int a, string b, double c)
    {
            Form2 frm = new Form2();
            frm.SomeTextBox.Tag = a;
            frm.SomeTextBox2.Tag = b;
            frm.SomeTextBox3.Tag = c;
            frm.ShowDialog();
    } 
    

    5- Using delegates. (This one is a little bit tricky).

     //in Form2
    public delegate void PassValues(int a, string b, double c);
    public PassValues passVals;
    
    private void PassDataThroughDelegate(int a, string b, double c)
    {
        if(passVals != null)
            passVals(a,b,c);
    }
    
    //in Form1
    private void ShowForm(int a, string b, double c)
    {
        Form2 frm = new Form2();
        frm.passVals = new Form2.PassValues(UseData);
        frm.ShowDialog();
    }
    
    private void UseData(int a, string b, double c)
    {
    } 
    

    My personal favorite ones are the properties, delegates and in some rare cases constructors.

    Alternatively, you can create a static class , put some properties in it, then use it in other forms.
    This is really helpful if all of your forms need to share some information. Since this is not a way to Pass data between the forms, I did not mention this method in those above.

    2) populate that comboBox with the members of that
    BankAccountCollection

    Once you passed the data between forms, using it for population is not hard.

    foreach(BankAccount acc in accounts)
       combobox1.Items.Add(acc.ToString());
    

    3) display that collection as items within the list?

    You can use event handler for combobox1 to do whatever you want with the selected item.

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

c# .Net 3.5 visual studio 2008, windows xp I have a main form in
I have a C# windows application which does the following: 1) the main form
Scenario I have a Windows Forms Application. Inside the main form there is a
I have a windows form on the main thread and another thread that does
I have a main form called mainForm - this runs my entire app. In
In a windows form application, on main form load, i have set a serial
I have a main form (MainForm) and a MDI child window (TFormChild). I want
I have a scenario. (Windows Forms, C#, .NET) There is a main form which
I have a main windows form and another form that inherits from it. The
I have a Switch to window button on my main form that I'd like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.