Solved

Raise an treeview_NodeMouseClick from treeview_AfterSelect in vb.net 2.0

Posted on 2009-04-08
6
866 Views
Last Modified: 2012-05-06
Hi,
I need to raise an treeview1_NodeMouseClick from treeview1_AfterSelect in vb.net 2.0
  AddHandler treeview1.NodeMouseClick, AddressOf treeview1_NodeMouseClick
does not work any suggestion?


Cheers
AddHandler treeview1.NodeMouseClick, AddressOf treeview1_NodeMouseClick

Open in new window

0
Comment
Question by:RIAS
  • 3
  • 3
6 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 500 total points
Comment Utility
AddHandler, doesn't raise an event, it only adds as the name implies an event handler to the object

Instead of raising the event oneself, I'd suggest create a method that can be called by both AfterSelect & NodeMouseClick, and do the work in that
public sub dostuff(TreeNode node)

end sub
 

public sub treeView1_AfterSelect(sender as object, e as TreeViewEventArgs) handles treeView1.AfterSelect

  dostuff(e.Node)

end sub
 

public sub treeView1_NodeMouseClick(sender as object, e as TreeNodeMouseClickEventArgs) handles treeView1.NodeMouseClick

  dostuff(e.Node)

end sub

Open in new window

0
 

Author Comment

by:RIAS
Comment Utility
Cheers mate but can you suggest raising singlemouseevent from afterselect event
0
 
LVL 15

Expert Comment

by:oobayly
Comment Utility
To be quite honest I'm not sure why you'd want to go through all the work of creating TreeNodeMouseClickEventArgs object, only to handle it immediately.

The problem is that to raise an event in a control, you need to call the On.... method, for example, TreeNodeMouseClick is called by OnOnNodeMouseClick. Unfortunately this method is protected, so unless you're creating a custom treeview, that injerits TreeView you don't have access to it.

You can of course use Reflection to call the OnNodeMouseClick method yourself, but you have to ask yourself "if it's this complicated, am I doing it the correct way?"

The code below uses reflection to get the Protected OnNodeMouseClick method from a TreeView control. It then creates TreeNodeMouseClickEventArgs, filling it with whatever data you wish. Finally it invokes the method on the TreeView that sent the event in the first place.
' This code goes in the AfterSelect event handler
 

' Create the EventArgs

Dim ev As New TreeNodeMouseClickEventArgs(e.Node, MouseButtons.Left, 1, 10, 10)
 

' Get the OnNodeMouseClick method

Dim onNodeClick As System.Reflection.MethodInfo = GetType(TreeView).GetMethod("OnNodeMouseClick", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
 

onNodeClick.Invoke(sender, New Object() {ev})

Open in new window

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:RIAS
Comment Utility
Hi,
Cheers for the solution but I get an signature mismatch error 'ev'
0
 

Author Closing Comment

by:RIAS
Comment Utility
Excellent
0
 
LVL 15

Expert Comment

by:oobayly
Comment Utility
Thanks for the points.

As for the reflection code, I can't understand why you should get a signature mismatch when invoking the method, it works straight away for me.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now