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

  • Home
  • SEARCH
  • 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 3225222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:18:52+00:00 2026-05-17T16:18:52+00:00

I have a groupbox which contains 10+ checkboxes. I would like to build a

  • 0

I have a groupbox which contains 10+ checkboxes. I would like to build a string that concatenates the Checkbox.Text of all the checkboxes which are checked.

Of course anytime the checked state changes for any of the checkboxes it will need to rebuild the string. How can I go about doing this?

Note: This needs to happen on the fly as checkboxes are checked/unchecked.

This is the idea I had going, but I feel like that there is a better way to do this – and also I’m not sure how I am going to remove the strings when an item is unchecked.

Any thoughts?

private void CheckBox_CheckedChanged(System.Object sender, System.EventArgs e)
{
    if (((CheckBox)sender).Checked)
    {
        switch (((CheckBox)sender).Name)
        {
            case "CheckBox1":
                sb = sb + "This is checkbox 1." + "\n";
                break;
            case "CheckBox2":
                sb = sb + "This is checkbox 2." + "\n";
                break;
            case "CheckBox3":
                sb = sb + "This is checkbox 3." + "\n";
                break;
            case "CheckBox4":
                sb = sb + "This is checkbox 4." + "\n";
                break;
            case "CheckBox5":
                sb = sb + "This is checkbox 5." + "\n";
                break;
            case "CheckBox6":
                sb = sb + "This is checkbox 6." + "\n";
                break;
            case "CheckBox7":
                sb = sb + "This is checkbox 7." + "\n";
                break;
            case "CheckBox8":
                sb = sb + "This is checkbox 8." + "\n";
                break;
            case "CheckBox9":
                sb = sb + "This is checkbox 9." + "\n";
                break;
            case "CheckBox10":
                sb = sb + "This is checkbox 10." + "\n";
                break;
        }
    }
    else
    {
    }
}
  • 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-17T16:18:53+00:00Added an answer on May 17, 2026 at 4:18 pm

    You can do something like this, assuming the check box name has the format ‘CheckBox#’:

    private void checkBox_CheckedChanged(object sender, EventArgs e)
    {
        var checkboxes = from c in groupBox1.Controls.OfType<CheckBox>()
                            where c.Checked
                            orderby int.Parse(c.Name.Substring(8))
                            select c;
    
        sb.Clear();
    
        foreach (var cb in  checkboxes)
        {
            sb.Append(string.Format("This is checkbox {0}", cb.Name.Substring(8)));
            sb.Append(Environment.NewLine);
        }
    
        textBox1.Text = sb.ToString();
    }
    

    If you don’t want to worry about the format of the checkbox names, you can use AlphanumComparator, though you’ll have to make some minor changes to the source to make it generic:

    AlphanumComparator<string> comparator = new AlphanumComparator<string>();
    
    var checkboxes = (from c in groupBox1.Controls.OfType<CheckBox>()
                      where c.Checked
                      select c).OrderBy(c => c.Name, comparator);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem like this, I have a groupBox which contains two radio buttons, when
I am using .NET winforms. I have a groupBox that contains a set of
I have a GroupBox that contains a stackpanel holding a textbox and a datagrid.
I have a Windows Forms app that contains a groupbox with about 30 controls.
I have a Windos::Forms::GroupBox which contains a Windows::Forms::ListView . When I add items, I
I have 2 groupboxes which I would like to customise a bit more, and
I have a groupbox that contains nested stack panels that aren't filling in the
I have a contact manager program that I'd like to design for multiple network
I have a groupbox that holds a flowlayout panel and the flowlayout panel holds
All, I have a GroupBox with multiple controls ( Button s, RadioButton s etc.)

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.