定义btnAdd事件:
private void btnAdd_Click(object sender, EventArgs e)
{
frmNodeItem nodeItem = new frmNodeItem();
if (this.MenuList.FocusedNode.ParentNode == null)
{
nodeItem.LoadStuData(this.MenuList.FocusedNode);
nodeItem.LoadClass(ManageSystem.BLL.ClsService.GetAllClsName());
if (nodeItem.ShowDialog()==DialogResult.OK)
{
this.MenuList.BeginUpdate();
string NodeName=nodeItem.m_SelectClsName;
TreeListNode node = this.MenuList.AppendNode(new object[] { null, null, NodeName }, MenuList.FocusedNode);
if (node != null)
{
MessageBox.Show("【" + NodeName + "】节点添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
this.MenuList.EndUpdate();
}
}
else
{
MessageBox.Show("请选择正确的节点进行操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}需要绑定btnAdd事件的控件:
private void tsmAdd_Click(object sender, EventArgs e)
{
btnAdd_Click(this.tsmAdd, e);
}
本文介绍了一个C#窗体应用程序中如何通过按钮点击事件来添加新的树节点。当点击添加按钮时,会打开一个对话框让用户选择要添加的节点名称,然后将新节点添加到指定的父节点下,并显示成功的提示信息。

被折叠的 条评论
为什么被折叠?



