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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:34:47+00:00 2026-06-02T05:34:47+00:00

I have a c# windows form application where I have a treeView inside a

  • 0

I have a c# windows form application where I have a treeView inside a tabPage of a tabControl which is a part of the main form.

For the tree view, I click on the items of the treeView which I want to select then some change happens based on my selected Items.

I am using the AfterSelect event for item selection and and the mouseUp event for undoing the selection.

The item selection and deselection happens right away with a single click (no problem). The other change with should happen based on the selected items happens after two clicks! A single click either on the item node or outside the node’s area do not trigger this change. I have to click again in order to see the change. That is wired. I am not using mouse double click events for this or something similar, I am only using the events I described above.

How can this be happening? and How to resolve it? Thanks.

EDIT: I am using my own multi-selection version of the treeView and I found (using debug) that when I get the selected nodes of the tree in the AfterSelect event after the first click is zero, then it is the number of selected nodes with the second click. How come this is happening when selected nodes are added and to the current selectedNodes list with every click in the overrided OnAfterSelect event of the treeView?

here is part of tree view code:

public List<TreeNode> SelectedNodes
        {
            get
            {
                return selectedNodes; 
            }

            set
            {
                removeSelectionFromNodes();
                selectedNodes = value;
                selectNodes();
            }
        }

   protected override void OnAfterSelect(TreeViewEventArgs e)
        {
            base.OnAfterSelect(e); 
            base.SelectedNode = null;
           List<MSTreeNode> nodes = new List<MSTreeNode>();
                   .
                   .
                   .
               removeSelectionFromNodes();
                selectedNodes.Clear();
                selectedNodes.AddRange(nodes);
                selectNodes();
        }
  • 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-02T05:34:51+00:00Added an answer on June 2, 2026 at 5:34 am

    I tried to use the MouseDown event instead of the AfterSelect event. I override it in the my own multi-selection version of the treeView and used in the c# application I am developing but still it did not work. I am not sure how mouse events really work. If not used carefully, you may see wired behaviors.

    Well, I ended up overriding the MouseUp and MouseUp events in my treeView subclass then I created an event which listens for changes in the selectedNodes list. If a change to the selectedNodes happnes in any of the mouse events this event is triggered. Then, I used the ChangedSelectedNodes event handler of the treeview instance in my application to do the other changes when there is a change in the node selection. This time it worked as expected.

    I posted this in hope that it would be beneficial to anyone else who ran into the same problem like me.

    P.S. Sometimes things do not work as you expect them to be and you just have fight and go through every other possibility until you find the solution.

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

Sidebar

Related Questions

I have a Windows Form Application in which clicking certain buttons create objects from
I have a windows form application which needs to be the TopMost. I've set
I have a windows form application which let an user to write in a
So I have an windows form application (client) which displays which groups belong to
I have created a windows form application which uses an SQL database. The database
I have a windows form application(c#) and an asp.NET web application which both access
I have a windows form application which has a text box and 3 buttons.
I have a windows form application which interacts with a remote database. the database
I have a windows form application. I have a query which return me datetime
I have a windows form application. On the main form a user will enter

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.