Click to See Complete Forum and Search --> : how to trap node clicking in tree view


swamivishal1
April 16th, 2005, 04:54 AM
hi all ,

i wants to know that

"how i can trap the node clicking event in a tree view in my asp.net/c# applicatoion"


do i have to write the treeview control right from the scratch ???? :cry:

thanks to all in advance
vishal

cilu
April 16th, 2005, 05:17 AM
Take a look at Click or/and AfterSelect events.

FoodBard
April 16th, 2005, 06:36 AM
you can't

use
tvw_MouseDown
tvw_KeyUp
and
TreeNode n = tvw.GetNodeAt(e.X, e.Y);

You get the idea.

swamivishal1
April 19th, 2005, 01:38 AM
hi friends ,

this is not working too;

when i tried the mouse down and the keyup events i get the messege that

Microsoft.Web.UI.WebControls does not contain a definition for the KeyUp event :sick:

i am using the ie web control in my application.

plz show me the way out of this situation.

thanx in advance
vishal

swamivishal1
April 19th, 2005, 01:44 AM
Take a look at Click or/and AfterSelect events.

dear guru,

i tried the click and afterselect event both but the mess was the same i.e

does not contain the definition ?????????? :sick:

thanx
vishal

Andy Tacker
April 19th, 2005, 01:57 AM
you should look into
AfterCheck event


private void OnCheckTreeView(object sender, TreeViewEventArgs e)
{
//get the whole path of the node and see if it is subnode?
int i = e.Node.FullPath.IndexOf(@"\");
///if yes
if(i >= 0)
{
//do something
//if it is checked
if(e.Node.Checked)
{
//do more
}
else
{
//do something else
}
}
else if(i == -1) //if it is not a sub node but a parent node
{
//go through all sub nodes
foreach (TreeNode tn in e.Node.Nodes)
{
//if the node is checked, check all underlying sub nodes
if(e.Node.Checked)
{
if (!tn.Checked)
tn.Checked = true;
}
else //else uncheck all underlying sub nodes
{
if(tn.Checked)
tn.Checked=false;
}
}
}
}

swamivishal1
April 19th, 2005, 02:33 AM
but i am not allowed to use the check boxes :cry:

Andy Tacker
April 19th, 2005, 04:46 AM
MAN! that's an example... dont use check box if you dont want... but before posting, you atleast try to understand the code.

ok?

swamivishal1
April 19th, 2005, 07:19 AM
thanx guru,

i tried the selectedindexchanged event and it served my purpose

many thanx to all of u

vishal