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 8479709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:06:27+00:00 2026-06-10T19:06:27+00:00

Rather new to C# so please forgive me if i am missing something simple

  • 0

Rather new to C# so please forgive me if i am missing something simple or am trying to just do this the wrong way.

I am creating another form to compliment my main form and it needs to pull some of the information from Main form on button click of Second form. The information on the Main for is stored in checkboxes and textboxes.

I have the textboxes working fine but cannot figure out how to pull the checkboxes tag data over along with the formatting. Main Form is working fine as is except I cannot figure out how to bring the checkbox data over as well.

This is the code i currently use to display the checkbox TAG data on my main form.

 //Statements to write checkboxes to stringbuilder
string checkBoxesLine = "\u2022 LIGHTS ";

foreach (Control control in pnlCheckBoxes.Controls)
{
    if (control is CheckBox)
    {
        CheckBox checkBox = (CheckBox)control;

        if (checkBox.Checked && checkBox.Tag is string)
        {
            string checkBoxId = (string)checkBox.Tag;
            checkBoxesLine += string.Format("{0}, ", checkBoxId);
        }
    }
}

This is the button i am using to open the new form and move the checkbox tag data and textbox.text data to the new form.

private void code_blue_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    trouble_shooting = tshooting_text.Text;
    services_offered = services_offered_text.Text;
    other_notes = other_notes_text.Text;
    cust_modem = cust_modem_text.Text;
    //Opens CODE BLUE form and pushes text to it.
    code_blue_form CBForm = new code_blue_form();
    CBForm.cust_name_cb = cust_name_text.Text;
    CBForm.cust_cbr_cb = cust_callback_text.Text;
    CBForm.cust_wtn_cb = cust_btn_text.Text;
    CBForm.cust_notes_cb = cust_modem + "\r\n" + trouble_shooting + "\r\n" + services_offered + "\r\n" + other_notes;

    CBForm.Show();
}

Here is my code for the Second form and how i am getting the information to populate textboxes on that form.

public partial class code_blue_form : Form
{
    public string cust_name_cb;
    public string cust_wtn_cb;
    public string cust_cbr_cb;
    public string cust_notes_cb;
    public string cust_modem_cb;
    public code_blue_form()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        cb_name_text.Text = cust_name_cb;
        cb_wtn_text.Text = cust_wtn_cb;
        cb_cbr_text.Text = cust_cbr_cb;
        cb_notes_text.Text = cust_notes_cb;
    }
  }
}

Please forgive the long post! Any ideas/direction on this would be greatly appreciated. Thanks!

  • 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-06-10T19:06:29+00:00Added an answer on June 10, 2026 at 7:06 pm

    I am not going to answer straight away using ur code. I find code smell. If I were you I would do this (but then if you are adamant about going with the same design, then you can tweak my code accordingly, no big deal, the bottom line is you get the idea how to do):

    void code_blue_link_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
    {
        var checkBoxIds = GetCheckBoxIds();
    
        cust_modem = cust_modem_text.Text;
        trouble_shooting = tshooting_text.Text;
        services_offered = services_offered_text.Text;
        other_notes = other_notes_text.Text;
    
        //take off underscore convetion and replace with camelCase convention.
        CodeBlueForm cbForm = new CodeBlueForm(checkBoxIds, cust_name_text.Text, 
                                               cust_callback_text.Text, 
                                               cust_btn_text.Text,
                                               cust_modem + "\r\n" + 
                                               trouble_shooting + "\r\n" + 
                                               services_offered + "\r\n" + 
                                               other_notes);
    
        cbForm.Show();
    }
    
    private List<int> GetCheckBoxIds()//even better naming required like GetFruitIds() 
    {                                 //(whatever the id is of) or even better Tag  
                                      //checkBoxes with the Fruit object iself and not ids.
        List<int> checkBoxIds = new List<int>(); //So you can call GetFruits();
        foreach (Control control in pnlCheckBoxes.Controls)
        {
            if (control is CheckBox)
            {
                CheckBox checkBox = (CheckBox)control;
    
                if (checkBox.Checked && checkBox.Tag is int) //tag them as ints. 
                    checkBoxIds.Add((int)checkBox.Tag);      //I hope ids are integers.
            }
        }
    
        return checkBoxIds;
    }
    
    public partial class CodeBlueForm : Form
    {
        List<int> checkBoxIds = new List<int>():
        string cust_cbr_cb; //should be private.
        string cust_name_cb;
        string cust_wtn_cb;
        string cust_notes_cb;
        string cust_modem_cb;
    
        public CodeBlueForm(List<int> ids, string cust_name_cb, string cust_wtn_cb, 
                            string cust_notes_cb, string cust_modem_cb)
        {
            InitializeComponent();
    
            this.checkBoxIds = ids;
            this.cust_name_cb = cust_name_cb;
            this.cust_wtn_cb = cust_wtn_cb;
            this.cust_notes_cb = cust_notes_cb;
            this.cust_modem_cb = cust_modem_cb;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            cb_name_text.Text = cust_name_cb; 
            cb_wtn_text.Text = cust_wtn_cb;
            cb_cbr_text.Text = cust_cbr_cb;
            cb_notes_text.Text = cust_notes_cb;
    
            string checkBoxesLine = "\u2022 LIGHTS ";        
            // if you dont require a lot of string formatting, then just:
            checkBoxesLine += string.Join(", ", checkBoxIds);
    
            // or go with your classical:
            //foreach (int id in checkBoxIds)
            //    checkBoxesLine += string.Format("{0}, ", checkBoxIds);
    
            //and do what u want with checkboxline here.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK I'm sure I'm missing something here, but please forgive me I'm new to
Please forgive this rather basic question, but I'm very new to Java and still
I am rather new to wx/python so please excuse if this is stupid or
I'm rather new to serious programming, so please forgive my dumbness, but I've failed
Please forgive me if this post is in the wrong place, but as your
I'm new to programming so please forgive me if this is a noob question!
Rather new to php, so sorry if this seems stupid. I'm really copying a
I'm rather new to C++ and I'm trying to understand the code over on
I'm rather new to jQuery and I'm trying to make a cool little menu
I am still shiny new to XNA, so please forgive any stupid question and

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.