Hello all,
I am trying to get the clicked nodes value and enter that value into a label.
I am sure I am on the right lines using the After_Select event, somthing like this.
private void treeView2_AfterSelect(object sender, EventArgs e)
{
Label2.Text = TreeView2.SelectedNode.Value;
}
Unfortunately this returns nothing. So basically say the rootnode of a treeview (Bound to sql server but this makes no difference) was "RT00000215", when the node is clicked to expand it I need the root node string to appear in a label.
Could anyone please help me?
Loading
VulpesPosted Sep 23, 2011, 6:18 AM
Chris JohnsonPosted Sep 23, 2011, 6:35 AM
Should share points with Satyapriya really but I don't think you can do that :-(
Thanks everyone!
*Edit - Final Solution.
void TreeView1_TreeNodeExpanded1(object sender, TreeNodeEventArgs e)
{
TextBox1.Text = e.Node.Text;
}
Simple when you know how ;-)
Chris JohnsonPosted Sep 23, 2011, 5:14 AM
I should of mentioned, however, it is a webform I am building.
My only problem now is that TreeViewEventArgs is from System.Windows.Forms namespace. After a little surfing I discovered that with a webform I should be using the System.Web.UI.WebControls namespace. Unfortunately this does not contain TreeViewEventArgs, any idea what I should use instead of TreeViewEventArgs?
Satyapriya NayakPosted Sep 23, 2011, 1:19 AM
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
label1.Text = treeView1.SelectedNode.Text;
}
private void button1_Click(object sender, EventArgs e)
{
treeView1.Nodes.Add("Student");
treeView1.Nodes[0].Nodes.Add("Raj");
treeView1.Nodes[0].Nodes.Add("Ravi");
treeView1.Nodes[0].Nodes.Add("Rahul");
}
}
}
Thanks
VulpesPosted Sep 22, 2011, 12:09 PM