Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C# WinForms: Resetting AfterSelect for TreeNode

Posted on 2012-09-04
5
Medium Priority
?
1,422 Views
Last Modified: 2012-09-05
I like the AfterSelect mouse event, but find it does not fire when you click that node a second time.  Is there a way to reset that?

Thanks.
0
Comment
Question by:newbieweb
  • 2
  • 2
5 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38365914
If you are selected the same node, then the answer no because it is already selected anyway.
One alternative (It will look weird in the UI any way) is to unselect the node after you execute the mouse event.
What kind of effect you are trying to achieve?
0
 

Author Comment

by:newbieweb
ID: 38366044
I want to open a dialog when the user clicks the node.  Once the dialog's been closed, the user can not open it again.
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 38366449
Handle the MouseUp() event of the TreeView and see if the TreeNode returned by GetNodeAt() is the same as TreeView.SelectedNode:
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            Console.WriteLine("AfterSelect(): " + e.Node.Text);
        }

        private void treeView1_MouseUp(object sender, MouseEventArgs e)
        {
            TreeNode tn = treeView1.GetNodeAt(e.X, e.Y);
            if (treeView1.SelectedNode == tn)
            {
                Console.WriteLine("Clicked on Already Selected Node: " + tn.Text);
            }
        } 

Open in new window

0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 38366885
You can use the treeview MouseClick  or MouseDoubleClick event if you are using the click event.
Sample code for MouseDoubleClick:
private void treeView1_MouseDoubleClick(object sender, MouseEventArgs e)
	{
	    // Get the selected node.
	    TreeNode node = treeView1.SelectedNode;
	    // Render message box or open your dialog here
	    MessageBox.Show(string.Format("You selected: {0}", node.Text));
	}

Open in new window

0
 

Author Closing Comment

by:newbieweb
ID: 38368582
This was the right answer.  I could not over-ride a double-click since the TreeView already uses double-click in its default behavior.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question