C#中TreeView控件怎样获取节点文字?
2013-12-14
展开全部
private void TVdepartment_ItemDrag(object sender, ItemDragEventArgs e)//左键拖动
{
if (e.Button == MouseButtons.Left)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
}
private void TVdepartment_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode"))
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void TVdepartment_DragDrop(object sender, DragEventArgs e)//拖动
{ //获得拖放中的节点
TreeNode moveNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
//根据鼠标坐标确定要移动到的目标节点
Point pt;
TreeNode targeNode;
pt = ((TreeView)(sender)).PointToClient(new Point(e.X, e.Y));
targeNode = this.TVdepartment.GetNodeAt(pt);
//如果目标节点无子节点则添加为同级节点,反之添加到下级节点的未端
TreeNode NewMoveNode = (TreeNode)moveNode.Clone();
if (targeNode.Nodes.Count == 0)
{
targeNode.Parent.Nodes.Insert(targeNode.Index, NewMoveNode);
}
else
{
targeNode.Nodes.Insert(targeNode.Nodes.Count, NewMoveNode);
}
//更新当前拖动的节点选择
TVdepartment.SelectedNode = NewMoveNode;
//展开目标节点,便于显示拖放效果
targeNode.Expand();
//移除拖放的节点
moveNode.Remove();
}
{
if (e.Button == MouseButtons.Left)
{
DoDragDrop(e.Item, DragDropEffects.Move);
}
}
private void TVdepartment_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode"))
{
e.Effect = DragDropEffects.Move;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void TVdepartment_DragDrop(object sender, DragEventArgs e)//拖动
{ //获得拖放中的节点
TreeNode moveNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode");
//根据鼠标坐标确定要移动到的目标节点
Point pt;
TreeNode targeNode;
pt = ((TreeView)(sender)).PointToClient(new Point(e.X, e.Y));
targeNode = this.TVdepartment.GetNodeAt(pt);
//如果目标节点无子节点则添加为同级节点,反之添加到下级节点的未端
TreeNode NewMoveNode = (TreeNode)moveNode.Clone();
if (targeNode.Nodes.Count == 0)
{
targeNode.Parent.Nodes.Insert(targeNode.Index, NewMoveNode);
}
else
{
targeNode.Nodes.Insert(targeNode.Nodes.Count, NewMoveNode);
}
//更新当前拖动的节点选择
TVdepartment.SelectedNode = NewMoveNode;
//展开目标节点,便于显示拖放效果
targeNode.Expand();
//移除拖放的节点
moveNode.Remove();
}
2013-12-14
展开全部
用TreeView的Afterselect事件
thie.lable1.Text = this.TreeView1.Selectnode.Text ;
就这样可以得到 节点的text ;
thie.lable1.Text = this.TreeView1.Selectnode.Text ;
就这样可以得到 节点的text ;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询