TreeView Node Click Handler Question

R

Rich

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
 
M

Marc Gravell

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
 
R

Rich

Marc said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top