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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:06:39+00:00 2026-05-20T01:06:39+00:00

I am creating a listview with a collections of ListViewItems, all with checkboxes. I

  • 0

I am creating a listview with a collections of ListViewItems, all with checkboxes. I want to check wich Item is checked. I know how to launch the ItemChecked event but the event is launched every time an ListViewItem is added to the ListView. How can I prevent this?


To help you understand what I want to do, here is a little info about the application.

I am building a application for Red Cross dispatchers. It will help them keep track of the units in the field. The application is used to, among other things, log the transmissions. When during a transmission a priorety transmission comes in, the current unit will be set on hold. This will be done by checking the checkbox belonging to the units ListViewItem.

By checking the checkbox, the object (with the type Unit) will set the property objUnit.onHold to true. When the checkbox is unchecked the property will be set to false again. Every 3 minutes the application will loop through all units to see if anyone is still on hold. If so, a messagebox will popup reminding the dispatcher of the unit on hold.

So you see, I have to be sure that the dispatcher really checked or unchecked the ListViewItem.

I hope someone can point me in the right direction.

  • 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-20T01:06:40+00:00Added an answer on May 20, 2026 at 1:06 am

    You can set a flag indicating that you are inserting an item and ignore the event if the flag is checked.

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Windows.Forms;
    
    class Form1 : Form
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    
        ListView listView;
        List<Unit> units;
        bool insertingItem = false;
    
        public Form1()
        {
            Controls.Add(listView = new ListView
            {
                Dock = DockStyle.Fill,
                View = View.Details,
                CheckBoxes = true,
                Columns = { "Name" },
            });
    
            Controls.Add(new Button { Text = "Add", Dock = DockStyle.Top });
            Controls[1].Click += (s, e) => AddNewItem();
    
            listView.ItemChecked += (s, e) =>
                {
                    Unit unit = e.Item.Tag as Unit;
                    Debug.Write(String.Format("Item '{0}' checked = {1}", unit.Name, unit.OnHold));
                    if (insertingItem)
                    {
                        Debug.Write(" [Ignored]");
                    }
                    else
                    {
                        Debug.Write(String.Format(", setting checked = {0}", e.Item.Checked));
                        unit.OnHold = e.Item.Checked;
                    }
                    Debug.WriteLine("");
                };
    
            units = new List<Unit> { };
        }
    
        Random Rand = new Random();
        int NameIndex = 0;
        readonly string[] Names = { "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten" };
        void AddNewItem()
        {
            if (NameIndex < Names.Length)
            {
                Unit newUnit = new Unit { Name = Names[NameIndex++], OnHold = Rand.NextDouble() < 0.6 };
                units.Add(newUnit);
                insertingItem = true;
                try
                {
                    listView.Items.Add(new ListViewItem { Text = newUnit.Name, Checked = newUnit.OnHold, Tag = newUnit });
                }
                finally
                {
                    insertingItem = false;
                }
            }
        }
    }
    
    class Unit
    {
        public string Name { get; set; }
        public bool OnHold { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView where I want each item to have an ID number
I'm creating a ListView where each list item has a LinearLayout which I would
I am creating a ListView dynamically and want to add two TextViews in a
am working in windows application with c#.Am creating the listview items dynamically..i want to
I'm creating a UserControl consisting of a TextBox and a ListView . I want
I'm creating a simple dialog with a ListView on it. I want to be
After creating a listview from VS2010 and adding it as a web part to
i am creating a listview with custom arrayadapter..but the problem is in tablet it's
I'm creating a ListView that contains two TextViews and an ImageView. I'm passing data
I am creating a simple RSS reader which displays headlines in ListView, downloading it

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.