开发者

Choosing the right eventhandler

I have a treeview which have as treenodes da开发者_如何学JAVAtabases 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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜