C# Treeview添加节点问题

来源:百度知道 编辑:UC知道 时间:2024/05/04 08:22:12
Treeview有个右键菜单
右键菜单有添加节点功能
怎么样点右键菜单的添加就可以添加节点,可以输入名字,并且并不知道会在哪个子节点添加

//contextMenuStrip1与treeView1关联,在节点上单击右键就给该节点添加子节点,在空白地方单击右键,就添加根节点
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication8
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.treeView1.LabelEdit = true;
}

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.treeView1.SelectedNode = e.Node;
flag = true;
contextMenuStrip1.Show(MousePosition);
}
}
bool flag = false;
private void 添加节点ToolStripMenuItem_Click(object sender, E