Vahan
Vahan

Reputation: 3268

Choosing the right eventhandler

I have a treeview which have as treenodes databases and databases have tables. I want to show listview when I click on the table name. Which eventhandler do I have to use for that? I tried treenodemouseclick, treenodemousedoubleclick and mouseclick handlers, but there was no effect. Please help.

Upvotes: 2

Views: 122

Answers (2)

mcw
mcw

Reputation: 3596

Are you talking about Windows.Forms.TreeView?

If so, and you are dealing with selection of nodes, you want the BeforeSelect or AfterSelect event.

BeforeSelect will let you determine which node is about to be selected and respond accordingly or even cancel the node selection if need be.

AfterSelect is best if you aren't trying to do anything specific with node selection, but you want to perform additional work for certain selections (or every selection).

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx

Upvotes: 1

Nemesis
Nemesis

Reputation: 444

Normally I use AfterSelectEvent which brings a reference to the selected node on the event argument:

    private void TvwTraining_AfterSelect(object sender, TreeViewEventArgs e)
    {

        if (e.Node.Parent == null)
        {
            // Its a top level node
            ParentObject ParentObj = (ParentObject)e.Node.Tag;
            ShowParentDetails(ParentObj);
        }

        else
        {
            // Its a child node
            ChildObject ChildObj = (ChildObject)e.Node.Tag;
            ShowChildDetails(ChildObj);
        }

    }

Then you just need to treat the event depending on the node you get.

Good luck, Nemesis

Upvotes: 1

Related Questions