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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:40:58+00:00 2026-05-15T21:40:58+00:00

My project is WinForms, C#. I have a form with TreeView with CheckBoxes set

  • 0

My project is WinForms, C#.

I have a form with TreeView with CheckBoxes set to true. There are a few root nodes each having multiple children nodes.

I’d like to have all children nodes to have the same checked/unchecked state as their parent. I wrote the following event handler:

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
  // return in case the event is induced by the code below
  if (e.Action == TreeViewAction.Unknown)
  {
    return;
  }
  System.Diagnostics.Debug.WriteLine(string.Format("Checked - {0}", e.Node.Checked));
  foreach (TreeNode subNode in e.Node.Nodes)
  {
    subNode.Checked = e.Node.Checked;
  }
}

However, this works quite strange when clicking on the parent quickly. I can easily reproduce this by quickly checking and unchecking parent so that subnodes are all checked while parent is already unchecked.

How to do this more correctly?

  • 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-15T21:40:58+00:00Added an answer on May 15, 2026 at 9:40 pm

    This is a bug introduced by the Vista version of the native TreeView control. It responds to a double-click by automatically toggling a check box. But without raising the BeforeCheck and AfterCheck events. The Windows Forms TreeView class wrapper wasn’t updated to deal with this problem.

    The fix is simple enough, you need to prevent the native control from seeing the double-click. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form, replacing the existing tree view.

    using System;
    using System.Windows.Forms;
    
    public class MyTreeView : TreeView {
      protected override void WndProc(ref Message m) {
        // Suppress WM_LBUTTONDBLCLK
        if (m.Msg == 0x203) { m.Result = IntPtr.Zero; }
        else base.WndProc(ref m);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Winforms project with a bunch of User controls. I'd like the
I have a .NET 3.5 WinForms project that uses several 3rd party controls and
I have a website (ASP.NET) and some winforms(.Net 2.0) for a project (written in
I have created a setup project in VS2008. My WinForms app uses .NET 2.0,
In Visual Studio 2008 in a C# WinForms project, there is a button on
I have a winforms projects and we use the command pattern. We are trying
Currently, we're using the following version numbering scheme for our C# winforms project: Major
In my winforms application, AppDomain.CurrentDomain.BaseDirectory is set to C:\Projects\TestProject\bin\Debug\ In my unit tests it
I'm writing a WinForms app which has two modes: console or GUI. Three projects
Project Darkstar was the topic of the monthly JavaSIG meeting down at the Google

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.