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.
Asked
Active
Viewed 114 times
2
-
It would help if you re-worded your question to be clearer. You mention a ListView and a TreeView as if they are the same, but they are different controls... – davisoa Apr 28 '11 at 16:49
-
In eventhandler when i clicked on treeview node table, i checked if treenode on which i clicked is table i add to controls new listview (it is for begening) but treenodemouseclick and mouseclick eventhandlers did not do anything, when i clicked on table names – Vahan Apr 28 '11 at 16:55
2 Answers
1
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

Nemesis
- 434
- 4
- 9
1
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

mcw
- 3,500
- 1
- 31
- 33