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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:09:17+00:00 2026-06-10T20:09:17+00:00

Hi all I am having 2 forms with checkedListBox . On my form1 I

  • 0

Hi all I am having 2 forms with checkedListBox . On my form1 I will select a few and click on submit where I will load form2, again on Form2 I will have a checkedListBox with the same Items as per in the first form1. Now I would like to check the form2 checkedListBox as per the form1 selected list.

I tried the following code

public class randomClass1
    {
        public bool IsChecked { get; set; }
        public string Name { get; set; }
        public randomClass1()
        {
            this.IsChecked = true;
            Name = "name1";
        }
    }

My button click event on form1 is as follows

 private void button1_Click(object sender, EventArgs e)
    {
        frmChild1 frm = new frmChild1();

        List<randomClass1> lst = new List<randomClass1>();

        for (int i = 0; i < checkedListBox1.Items.Count; i++)
        {
            lst.Add(new randomClass1());
        }

        for (int i = 0; i < checkedListBox1.Items.Count; i++)
        {
            randomClass1 obj = (randomClass1)checkedListBox1.Items[i];
            if (checkedListBox1.GetItemChecked(i))
            {
                checkedListBox1.SetItemChecked(i, obj.IsChecked);
            }
            else
            {
                obj.IsChecked = false;
                checkedListBox1.SetItemChecked(i, obj.IsChecked);
            }
        }

        frm.loadFrom(lst); //unable to retrieve the same when I checked 
        //frm.loadFrom(lst);
        frm.Show();
    }

In form2 I tried of creating the same class but I am unable to access that class, can some one help me what should I code in form2 inorder to get the selected items

  • 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-10T20:09:19+00:00Added an answer on June 10, 2026 at 8:09 pm

    There are a number of ways to solve this problem.

    First off, I’m assuming that Form1 has access to the Form2 object. If it doesn’t, something else will need to act as a middleman to get the checkstate data from Form1 to Form2.

    Assuming it does, all you need is a public method like:

    public void SetList(List<bool> checkmarks)
    {
        for (int i = 0; i < checkmarks.Count; ++i)
        {
            checkedListBox1.SetItemChecked(i, checkmarks[i]);
        }
    }
    

    or however you want that to work. My quick solution is that in Form1 I’ve got a button click handler that makes a Form2, shows it and sets the list. But whatever… you just need to be able to communicate those states between the two forms. Here’s that code:

    private void button1_Click(object sender, EventArgs e)
    {
        var list = new List<bool>();
        for (int i = 0; i < checkedListBox1.Items.Count; ++i)
        {
            list.Add(checkedListBox1.GetItemChecked(i));
        }
        Form2 f2 = new Form2();
        f2.Show();
        f2.SetList(list);
    }
    

    In production code I’d probably opt for a pattern like MVC and do things differently but this will work.

    The idea is no different if you use your randomClass1 class rather than my List<bool>.

    Obviously here I’ve made assumptions such as that both checkedlistboxes have pre-populated items and they’re in the same order, etc. etc.

    You could certainly send all that data across and create the items dynamically as well. It wasn’t clear from your question which you were doing but I assumed the list was already populated with items.

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

Sidebar

Related Questions

We have all seen countless instances of forms with a select drop down having
I have 3 select boxes and all are having same value (clones) & created
I have one scenario where I need to select all files having aliencoders.numeric-digits like
I want to create a bunch of forms that all have the same properties
Am doing a project in C#.net.I have to use the same forms to all
I am new to Windows forms and having an issue handling all the user
I am having serious trouble with trying to get all the forms on a
I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates
When you sort on column a descending, it will put all records having a
Hi all i am doing an application in win forms I am having a

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.