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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:39:31+00:00 2026-05-26T06:39:31+00:00

I’m having strange issues with the check box control in C# .Net My code

  • 0

I’m having strange issues with the check box control in C# .Net
My code below shows all logic that is required – _itemsChecked is a private dictionary containing all of the _fixtures and whether they are true or false (checked or un checked)

What I want is to be able to search my check list whilst retaining those which have been checked previously. If a checked item is included in the search results I want it to be checked.

The code nearly works! But for some reason boxes are randomly checked here and there, and it appears to work through debug but when the screen returns to the control it then hasn’t worked.

Sure I’m missing something very simple.

My logic is:

DataSource includes those which match the typed search query,
Iterate through this list and check if the Guid is true in the dictionary.
If it is true then we set it as checked.

Hope I have provided adequate information.

Many thanks in advance.

 private void searchTextBox_KeyUp(object sender, EventArgs e)
        {
            lst.DataSource = _fixtures
                .OrderBy(f => 
                    f.Description)
                .Where(f => 
                    f.Description.ToLower().Contains(searchFixturesTextBox.Text.ToLower()))
                .ToList();

            lst.DisplayMember = "Description";

            for (var i = 0; i < lst.Items.Count; i++)
                if(_itemsChecked.Contains(new KeyValuePair<Guid, bool>(((Fixture)lst.Items[i]).Guid, true)))
                    lst.SetItemChecked(i, true);
        }

        void lst_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            var selectedItem = ((ListBox) sender).SelectedItem as Fixture;

            if (selectedFixtureItem != null)
                _itemsChecked[selectedItem.Guid] = e.CurrentValue == CheckState.Unchecked;
        }
  • 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-26T06:39:31+00:00Added an answer on May 26, 2026 at 6:39 am

    So I put this together from a few examples I found. The majority of the work came from How do I make a ListBox refresh its item text?

    public class Employee
    {
       public string Name { get; set; }
       public int Id { get; set; }
       public bool IsChecked { get; set; }
    
       public override string ToString()
       {
          return Name;
       }
    }
    
    public partial class Form1 : Form
    {
       // Keep a bindable list of employees
       private BindingList<Employee> _employees;
    
       public Form1()
       {
          InitializeComponent();
          // Load some fake employees on load
          this.Load += new EventHandler(Form1_Load);
          // Click once to trigger checkbox changes
          checkedListBox1.CheckOnClick = true;
          // Look for item check change events (to update there check property)
          checkedListBox1.ItemCheck += 
             new ItemCheckEventHandler(CheckedListBox_ItemCheck);
       }
    
       // Load some fake data
       private void Form1_Load(object sender, EventArgs e)
       {
          _employees = new BindingList<Employee>();
          for (int i = 0; i < 10; i++)
          {
             _employees.Add(new Employee() 
                { Id = i, Name = "Employee " + i.ToString() });
          }
    
          // Display member doesnt seem to work, so using ToString override instead
          //checkedListBox1.DisplayMember = "Name";
          //checkedListBox1.ValueMember = "Name";
          checkedListBox1.DataSource = _employees;
    
          // Another example databind to show selection changes
          txtId.DataBindings.Add("Text", _employees, "Id");
          txtName.DataBindings.Add("Text", _employees, "Name");
       }
    
       // Item check changed, update the Employee IsChecked property
       private void CheckedListBox_ItemCheck(object sender, ItemCheckEventArgs e)
       {
          CheckedListBox clb = sender as CheckedListBox;
          if (clb != null)
          {
             Employee checked_employee = clb.Items[e.Index] as Employee;
             if (checked_employee != null)
             {
                checked_employee.IsChecked = (e.NewValue == CheckState.Checked);
             }
          }
       }
    
       // Just a simple test that removes an item from the list, rebinds it
       // and updates the selected values
       private void btnChangeList_Click(object sender, EventArgs e)
       {
          _employees.RemoveAt(1);
          checkedListBox1.DataSource = _employees;
    
          for (var i = 0; i < checkedListBox1.Items.Count; i++)
          {
             Employee employee_to_check = checkedListBox1.Items[i] as Employee;
             if (employee_to_check != null)
             {
                checkedListBox1.SetItemChecked(i, employee_to_check.IsChecked);
             }
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string

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.