c# winform 程序TreeView解决方案
c# winform 程序TreeView
本人刚接触winform对TreeView 不熟悉。。谁能给源码介绍TreeView的用法。。增、删、改和右键功能。。
要求要在树的本身上进行操作。。
------最佳解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace XMLOperate
{
public partial class Form1 : Form
{
//声明XML文档对象模型
XmlDocument document;
//选中的节点
TreeNode selectNode;
public Form1()
{
InitializeComponent();
//实例化文档模型
this.document = new XmlDocument();
}
//退出
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
//添加根元素还是子元素
bool isPater = true;
//添加
private void btnAppend_Click(object sender, EventArgs e)
{
try
{
//没果没有根元素
if (isPater)
{
string root = this.txtElement.Text.Trim();
this.trvXml.Nodes.Add(root);
this.document.LoadXml("<" + root + "></" + root + ">");
this.isPater = false;
this.btnInsert.Enabled = true;
this.btnRemove.Enabled = true;
this.btnReplace.Enabled = true;
this.btnSave.Enabled = true;
本人刚接触winform对TreeView 不熟悉。。谁能给源码介绍TreeView的用法。。增、删、改和右键功能。。
要求要在树的本身上进行操作。。
------最佳解决方案--------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
namespace XMLOperate
{
public partial class Form1 : Form
{
//声明XML文档对象模型
XmlDocument document;
//选中的节点
TreeNode selectNode;
public Form1()
{
InitializeComponent();
//实例化文档模型
this.document = new XmlDocument();
}
//退出
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
//添加根元素还是子元素
bool isPater = true;
//添加
private void btnAppend_Click(object sender, EventArgs e)
{
try
{
//没果没有根元素
if (isPater)
{
string root = this.txtElement.Text.Trim();
this.trvXml.Nodes.Add(root);
this.document.LoadXml("<" + root + "></" + root + ">");
this.isPater = false;
this.btnInsert.Enabled = true;
this.btnRemove.Enabled = true;
this.btnReplace.Enabled = true;
this.btnSave.Enabled = true;