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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:47:05+00:00 2026-05-24T03:47:05+00:00

I have a Winform application I’m modifying for a friend. It has a listview

  • 0

I have a Winform application I’m modifying for a friend. It has a listview and wants me to add a checkbox to each row and make them mutually exclusive. So in my testing of how to make it work I found a strange behavior and as hopping someone could tell me what I’m missing.

If I display the List view with no checkbox checked. When I click right on the checkbox I cannot get it to check, but the row dose get selected. If I click on the item (the name in this case) in the column it does get checked and selected.

No matter where I click on a row, any checkboxes in rows not selected will be uncheck. Here is my little test program. I’m using .NET 4


public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e) {
        TestListView.Items.Add("Bob");
        TestListView.Items.Add("Ann");
        TestListView.Items.Add("Frank");
    }

    void TestListView_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) {
        ListViewItem currentItem = TestListView.GetItemAt(e.X, e.Y);
        if (currentItem != null) {
            foreach (ListViewItem item in TestListView.Items) {
                if (item.Text == currentItem.Text) {
                    item.Checked = true;
                    item.Selected = !currentItem.Selected;
                }
                else 
                    item.Checked = false;
            }
        }
    }
}   
  • 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-24T03:47:07+00:00Added an answer on May 24, 2026 at 3:47 am

    I’m currently having a very similar issue as well, however in response to Timwi it’s not the code doing the unchecking. I’ve been stepping through it very slowly and as the code fires when clicking on a checkbox, it states that it has checked it. But when the form resumes, it is unchecked again. After reading Timwi post, he lead me onto the answer. It’s not the code doing the unchecked, but the winforms event firing afterwards that unchecks the box. This fixes it:

    My code is:

    private bool allowCheck = false;
    private bool preventOverflow = true;
    
    private void lstvwRaiseLimitStore_MouseClick(object sender, MouseEventArgs e)
        {
            preventOverflow = false;
            ListViewItem item = lstvwRaiseLimitStore.HitTest(e.X, e.Y).Item;
            if (item.Checked)
            {
                allowCheck = true;
                item.Checked = false;
            }
            else
            {
                allowCheck = true;
                item.Checked = true;
            }
        }
    
    private void lstvwRaiseLimitStore_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            if (!preventOverflow)
            {
                if (!allowCheck)
                {
                    preventOverflow = true;
                    e.Item.Checked = !e.Item.Checked;
                }
                else
                    allowCheck = false;
            }
        }
    

    So what it is doing, first I have to set a flag to prevent overflow, otherwise when the form is built or when you uncheck windows checking the box, it keeps looping the code and will eventually stack overflow. Next flag is the actual allow checking of the checkbox via your code and not via another method.

    Clicking on them item, it locates where the click was and then sets the flag to allow a check to be done. The code then checks the box and the item checked section kicks off, becuase it was done by our code, it does nothing but reset the allowcheck flag.

    If you clicked on a line, it does nothing else, however if it was a checkbox, at the end of our code, the Windows function kicks off and tries to check the box, becuase the allowcheck flag is false, the code first sets a flag to say I’m already preventing a check and then resets the check back to it’s intial status. Becuase this is done, the itemchecked event kicks off again, but the code has set the flag to prevent it from doing anything. Then the code finishes and it has prevented windows from checking the check box and only allowed our code.

    Hope it helps!

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

Sidebar

Related Questions

I have a C# WinForm application that has a few images on it. I
I have a C# WinForm application where I am using a ListView to show
I have a WinForm application that has a list view in it. What I
I have a C# winform application. it has many forms with different functionalities. These
I have a winform application and this winform application has created few files. I
I have c# winform application and one WPF user control. How i can add
I have a winform application with two textboxes. The textboxes are multilined and has
I have a winform application which has a dynamic number (based on a database
I have a Winform application built with C# and .Net 2.0. I have a
I have my winform application gathering data using databinding. Everything looks fine except that

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.