winform TREEVIEW 与XMLwinform 中如何动态添加一个节点?一般用什么判断点击了TREEVIEW节点后做出的相应行为事件,或者说switch()括号里应该放treeview哪个属性来做判断最好?

题目
winform TREEVIEW 与XML

winform 中如何动态添加一个节点?一般用什么判断点击了TREEVIEW节点后做出的相应行为事件,或者说switch()括号里应该放treeview哪个属性来做判断最好?


相似考题
参考答案和解析

给出3段代码,分别是TreeView2XML、XML2TreeView和TreeView2MenuStrip。

一、TreeView2XML

#region TreeView 2 XML private void btnSave_Click(object sender, EventArgs e) { //将TreeView保存到XML文件中 if (this.dlgSave.ShowDialog() == DialogResult.OK) { XmlDocument doc = new XmlDocument(); doc.LoadXml("<Menu></Menu>"); XmlNode root = doc.DocumentElement; doc.InsertBefore(doc.CreateXmlDeclaration("1.0", "utf-8", "yes"), root); TreeNode2Xml(this.treeView1.Nodes, root); doc.Save(dlgSave.FileName); } } private void TreeNode2Xml(TreeNodeCollection treeNodes, XmlNode xmlNode) { XmlDocument doc = xmlNode.OwnerDocument; foreach (TreeNode treeNode in treeNodes) { XmlNode element = doc.CreateNode("element", "Item", ""); XmlAttribute attr = doc.CreateAttribute("Title"); attr.Value = treeNode.Text; element.Attributes.Append(attr); element.AppendChild(doc.CreateCDataSection(treeNode.Tag.ToString())); xmlNode.AppendChild(element); if (treeNode.Nodes.Count > 0) { TreeNode2Xml(treeNode.Nodes, element); } } } #endregion

二、XML 2TreeView

#region XML 2 TreeView private void btnLoad_Click(object sender, EventArgs e) { //从XML中读取数据到TreeView if (this.dlgOpen.ShowDialog() == DialogResult.OK) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(dlgOpen.FileName); XmlNodeList xmlNodes = xmlDoc.DocumentElement.ChildNodes; this.treeView1.BeginUpdate(); this.treeView1.Nodes.Clear(); XmlNode2TreeNode(xmlNodes, this.treeView1.Nodes); this.treeView1.EndUpdate(); } } private void XmlNode2TreeNode(XmlNodeList xmlNode, TreeNodeCollection treeNode) { foreach (XmlNode var in xmlNode) { if (var.NodeType != XmlNodeType.Element) { continue; } TreeNode newTreeNode = new TreeNode(); newTreeNode.Text = var.Attributes["Title"].Value; if (var.HasChildNodes) { if (var.ChildNodes[0].NodeType == XmlNodeType.CDATA) { newTreeNode.Tag = var.ChildNodes[0].Value; } XmlNode2TreeNode(var.ChildNodes, newTreeNode.Nodes); } treeNode.Add(newTreeNode); } } #endregion

三、TreeView 2 Menu

#region TreeView 2 Menu private void btnRecreateMenu_Click(object sender, EventArgs e) { //根据TreeView生成层次结构的菜单 this.contextMenuStrip1.Items.Clear(); TreeView2Menu(this.treeView1.Nodes, this.contextMenuStrip1.Items); } private void TreeView2Menu(TreeNodeCollection nodes, ToolStripItemCollection items) { foreach (TreeNode node in nodes) { ToolStripMenuItem menu = new ToolStripMenuItem(); menu.Text = node.Text; menu.Tag = node.Tag; items.Add(menu); if (node.Nodes.Count > 0) { TreeView2Menu(node.Nodes, menu.DropDownItems); } else { menu.Click += new EventHandler(menu_Click); } } } #endregion
更多“winform TREEVIEW 与XML winform中如何动态添加一个节点?一般用什么判断点击了TREEVIEW节点后做出的相应行为事件,或者说switch()括号里应该放treeview哪个属性来做判断最好?”相关问题
  • 第1题:

    属性应该在哪个节点完成AP样车性能测试报告,AP样车属性目标评估?()

    • A、SC节点
    • B、PA节点
    • C、PR节点
    • D、CC节点

    正确答案:C

  • 第2题:

    treeView1.Nodes[1].Nodes[0]代表了控件treeView1的()。 

    • A、第1个根节点的第1个子节点
    • B、第1个根节点的第2个子节点
    • C、第2个根节点的第1个子节点
    • D、第2个根节点的第2个子节点

    正确答案:C

  • 第3题:

    DOM定义了XML文档的接口、属性和方法,如其中的XMLDoc对象代表XML文档的节点,该对象的 ()方法,返回其所对应的节点对象类型。


    正确答案:GetNodeType

  • 第4题:

    创建粒子与模型物体的碰撞之后,生成一个geoConnector节点,如果需要降低粒子碰撞模型之后的反弹程度,应该如何修改?()

    • A、提高geoConnector节点的tessellation Factor属性值
    • B、提高geoConnector节点的resilience属性值
    • C、降低geoConnector节点的resilience属性值
    • D、提高geoConnector节点的friction属性值
    • E、降低geoConnector节点的friction属性值

    正确答案:C

  • 第5题:

    如果设treeView1=newTreeView(),则treeView1.Nodes.Add("根节点")返回的是一个()类型的值。

    • A、TreeNode
    • B、int
    • C、string
    • D、TreeView

    正确答案:B

  • 第6题:

    如果设treeView1=new TreeView(),则treeView1.Nodes.Add("根节点")返回的是一个()类型的值。

    • A、TreeNode
    • B、int
    • C、string
    • D、TreeView

    正确答案:A

  • 第7题:

    如果要求只能通过在 Microsoft Visual Studio 中进行设计而不写任何代码的情况下,下面那个数据源能用于 TreeView Web 服务器控件的数据源?()

    • A、Site Map
    • B、SQL Server database
    • C、XML File
    • D、Microsoft Access database
    • E、File system

    正确答案:B

  • 第8题:

    单选题
    TreeView控件的节点集合保存在()属性之中。
    A

    Items

    B

    Nodes

    C

    Controls

    D

    ImageList


    正确答案: A
    解析: 暂无解析

  • 第9题:

    多选题
    You create a Web Form that contains a TreeView control. The TreeView control allows users to navigate within the Marketing section of your Web site. The following XML defines the site map for your site. You need to bind the TreeView control to the site map data so that users can navigate only within the Marketing section. Which three actions should you perform?()
    A

    Add a SiteMapDataSource control to the Web Form and bind the TreeView control to it.

    B

    Add a SiteMapPath control to the Web Form and bind the TreeView control to it.

    C

    Embed the site map XML within the SiteMap node of a Web.sitemap file.

    D

    Embed the site map XML within the AppSettings node of a Web.config file.

    E

    Set the StartingNodeUrl property of the SiteMapDataSource control to ~/Marketing.aspx.

    F

    Set the SkipLinkText property of the SiteMapPath control to Sales.


    正确答案: A,E
    解析: 暂无解析

  • 第10题:

    单选题
    下列四个选项都是TreeView控件的事件,()表示“当用户拖动一个对象并且进入到一个控件时发生”。
    A

    DragWithin

    B

    DragLeave

    C

    DragEnter

    D

    DragDrop


    正确答案: A
    解析: 暂无解析

  • 第11题:

    单选题
    如果设treeView1=newTreeView(),则treeView1.Nodes.Add("根节点")返回的是一个()类型的值。
    A

    TreeNode

    B

    int

    C

    string

    D

    TreeView


    正确答案: B
    解析: 暂无解析

  • 第12题:

    判断题
    TreeView控件某个节点的Nodes.Count属性值为0,说明这个节点没有下级子节点。
    A

    B


    正确答案:
    解析: 暂无解析

  • 第13题:

    下列可以用来存储图像供其它对象使用的控件是()。

    • A、ToolBar
    • B、StatursBar
    • C、ImageList
    • D、TreeView

    正确答案:C

  • 第14题:

    TreeView控件某个节点的Nodes.Count属性值为0,说明这个节点没有下级子节点。


    正确答案:正确

  • 第15题:

    关于XML DOM中方法的描述,下列说法正确的有()。

    • A、createElement()方法创建一个元素节点
    • B、setAttribute()方法为一个元素创建一个属性节点
    • C、setAttributeNode()将属性节点添加到一个元素中
    • D、replaceData()使用新节点替换一个已经存在的节点

    正确答案:A,B,C

  • 第16题:

    站点导航控件,下面说法不正确的是()

    • A、站点导航控件可以让用户快速的定位到某一页面
    • B、TreeView和Menu控件都会显示数据文件中所有节点信息
    • C、使用SiteMapPath控件时不需要指定其数据源文件
    • D、SiteMapPath控件可以选择XML文件或者是站点地图作为数据源

    正确答案:D

  • 第17题:

    如果设treeView1=new TreeView(),TreeNode node=new TreeNode("根结点"),则treeView1.Nodes.Add(node)返回的是一个类型的值。()

    • A、TreeNode;
    • B、int;
    • C、string;
    • D、TreeView;

    正确答案:B

  • 第18题:

    You create a Web Form that contains a TreeView control. The TreeView control allows users to navigate within the Marketing section of your Web site. The following XML defines the site map for your site. You need to bind the TreeView control to the site map data so that users can navigate only within the Marketing section. Which three actions should you perform?()

    • A、Add a SiteMapDataSource control to the Web Form and bind the TreeView control to it.
    • B、Add a SiteMapPath control to the Web Form and bind the TreeView control to it.
    • C、Embed the site map XML within the SiteMap node of a Web.sitemap file.
    • D、Embed the site map XML within the AppSettings node of a Web.config file.
    • E、Set the StartingNodeUrl property of the SiteMapDataSource control to ~/Marketing.aspx.
    • F、Set the SkipLinkText property of the SiteMapPath control to Sales.

    正确答案:A,C,E

  • 第19题:

    单选题
    如果设treeView1=new TreeView(),TreeNode node=new TreeNode("根结点"),则treeView1.Nodes.Add(node)返回的是一个类型的值。()
    A

    TreeNode;

    B

    int;

    C

    string;

    D

    TreeView;


    正确答案: A
    解析: 暂无解析

  • 第20题:

    单选题
    如果设treeView1=new TreeView(),则treeView1.Nodes.Add("根节点")返回的是一个()类型的值。
    A

    TreeNode

    B

    int

    C

    string

    D

    TreeView


    正确答案: B
    解析: 暂无解析

  • 第21题:

    单选题
    当用户在TreeView控件上选择了一个节点,其处理程序代码应编写在()事件中。
    A

    BeforeExpand

    B

    AfterSelect

    C

    Click

    D

    MouseDown


    正确答案: D
    解析: 暂无解析

  • 第22题:

    单选题
    创建粒子与模型物体的碰撞之后,生成一个geoConnector节点,如果需要降低粒子碰撞模型之后的反弹程度,应该如何修改?()
    A

    提高geoConnector节点的tessellation Factor属性值

    B

    提高geoConnector节点的resilience属性值

    C

    降低geoConnector节点的resilience属性值

    D

    提高geoConnector节点的friction属性值

    E

    降低geoConnector节点的friction属性值


    正确答案: A
    解析: 暂无解析

  • 第23题:

    单选题
    treeView1.Nodes[1].Nodes[0]代表了控件treeView1的()。
    A

    第1个根节点的第1个子节点

    B

    第1个根节点的第2个子节点

    C

    第2个根节点的第1个子节点

    D

    第2个根节点的第2个子节点


    正确答案: A
    解析: 暂无解析