Connecting Tech Pros Worldwide Forums | Help | Site Map

TreeView Node Click Handler Question

Rich
Guest
 
Posts: n/a
#1: Nov 28 '06
Another simple question from a noob.

I would like to use a tree view and perform actions when the user
clicks on nodes in the tree.

The C# IDE sets up many things automatically - for example when you
double-click on a button control in the designer it creates a function
for the button click handler and takes you to the code. Is there a
means for the IDE to create functions for things like clicks on tree
nodes?

I can make this work by manually adding a function, but this requires
me to edit the "Windows Form Designer Generated Code" to assign my
handler function to the node mouse click event handler for the tree
view. The comments for this region say "do not modify the contents of
this method with the code editor", which tells me I probably shouldn't
be doing it this way.

What is the "right" way to do this?

Thanks,
Rich


Marc Gravell
Guest
 
Posts: n/a
#2: Nov 28 '06

re: TreeView Node Click Handler Question


Select the tree-view, and change to the events view (the lightning button on
the properties panel); then scroll to the event you want (e.g.
NodeMouseClick) and either double-click the empty cell, or type the name you
want.

Alternatively you can hook up events manually *outside* of the designer code
by simply tweaking the constructor. But don't mess with InitializeComponent
unless you know what you are doing. The IDE can be flakey even when treated
gently, and it doesn't like that very much.

Marc


Rich
Guest
 
Posts: n/a
#3: Nov 28 '06

re: TreeView Node Click Handler Question



Marc Gravell wrote:
Quote:
Select the tree-view, and change to the events view (the lightning button on
the properties panel); then scroll to the event you want (e.g.
NodeMouseClick) and either double-click the empty cell, or type the name you
want.
>
Alternatively you can hook up events manually *outside* of the designer code
by simply tweaking the constructor. But don't mess with InitializeComponent
unless you know what you are doing. The IDE can be flakey even when treated
gently, and it doesn't like that very much.
>
Marc
Perfect - thanks Marc!

Closed Thread