Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Having a problem with treeview to listview

$
0
0

How do I go about getting the value of a selected  attribute in tree view and show  and edit it from the list view?

I have the attribute name listed in columns, but nothing shows under them.

Here is a sample XML

<?xml version="1.0" encoding="iso-8859-1"?><mission_script><!--<xi:include href="/data/levels/common/common.xml#xpointer(/common/*)"/>--><briefing text_id="mission_01_briefing" map_texture="/data/textures/atlas_gui/mission_gfx/briefing_map_m01"><![CDATA[This is the start of the briefing]]><briefing_text txt_id="briefing_m01_strategic" headline_id="briefing_strategic_hl" anchor="obj1" pos="0.074 0.246 -2" type="objective" /><briefing_text txt_id="briefing_m01_tactical" headline_id="briefing_tactical_hl" anchor="obj2" pos="0.12 0.187 -2" type="objective" /><briefing_text txt_id="objectives_m01" headline_id="objectives_hl" anchor="obj3" pos="0.206 0.012 -2" type="objective" /><briefing_text txt_id="insertions_m01" headline_id="insertions_hl" anchor="obj4" pos="0.174 0.246 -2" type="objective" /><briefing_text txt_id="tips_m01" headline_id="tips_hl" anchor="obj5" pos="0.074 0.246 -2" type="objective" /><![CDATA[This is the start of the map setup]]><map_text txt_id="loc_sp_mission01_01" pos="0.67 0.02 0.4" type="small" /><map_text txt_id="loc_sp_mission01_02" pos="0.65 0.155 0.3" type="small" /><map_text txt_id="loc_sp_mission01_03" pos="0.673 0.255 0.4" type="small" /><map_text txt_id="loc_sp_mission01_04" pos="0.345 0.2 0.1" type="small" /><map_text txt_id="loc_sp_mission01_05" pos="0.55 0.5 0.21" type="small" /><map_text txt_id="loc_sp_mission01_06" pos="0.5 0.82 0" type="small" /><map_text txt_id="1" pos="0.345 0.25 0.1" type="small" /><map_text txt_id="4" pos="0.673 0.315 0.1" type="small" /><map_text txt_id="5" pos="0.86 0.09 0.1" type="small" /><![CDATA[This is the actor and video start]]><actor name="m01_briefing" /><video name="data/movies/m01_video.bik" /></briefing><location name="droprope_bad" shape="sphere" pos="10077 11727 4719" radius="1100" /><!-- insertion drops rope --><trigger name="droprope" interval="0.4" preserved="false"><condition type="UnitInLocation" location="droprope" vehicle_id="insert" amount="1" /><event name="droppope" /></trigger><trigger name="droprope_b" interval="0.4" preserved="false"><condition type="UnitInLocation" location="droprope_b" vehicle_id="insert" amount="1" /><event name="droppope" /></trigger><!-- insertion helicopter leaves --><trigger name="insert_leave" interval="0.8" preserved="false"><condition type="UnitInTransport" vehicle_id="insert" equal="0" /><event name="insert_leave" /></trigger><!-- the first easy guys you shoot in the back or something --><trigger name="t_guy02" interval="1.0" preserved="false"><condition type="UnitInLocation" location="guy02" player_type="campaign_team" amount="1" /><event name="spawn_guy02" /></trigger><event name="spawn_guy02"><element type="ActivateGroup" group_id="guy02" /><element type="StopTrigger" name="t_guy02" /></event><!-- spawn enemy convoy --><trigger name="enemy_convoy" interval="0.8" preserved="false"><if_any><condition type="UnitInLocation" location="enemy_convoy01" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_convoy02" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_convoy03" player_type="campaign_team" amount="1" /></if_any><event name="enemy_convoy" /></trigger><!-- spawn enemy village --><trigger name="enemy_village" interval="0.8" preserved="false"><if_any><condition type="UnitInLocation" location="enemy_village01" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_village02" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_village03" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_village04" player_type="campaign_team" amount="1" /></if_any><event name="enemy_village" /></trigger><!-- spawn enemy bridge --><trigger name="enemy_bridge" interval="0.8" preserved="false"><if_any><condition type="UnitInLocation" location="enemy_bridge01" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_bridge02" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_bridge03" player_type="campaign_team" amount="1" /></if_any><event name="enemy_bridge" /></trigger><!-- spawn enemy outpost --><trigger name="enemy_outpost" interval="0.8" preserved="false"><if_any><condition type="UnitInLocation" location="enemy_outpost01" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_outpost02" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_outpost03" player_type="campaign_team" amount="1" /></if_any><event name="enemy_outpost" /></trigger><!-- spawn enemy cache --><trigger name="enemy_cache" interval="0.8" preserved="false"><if_any><condition type="UnitInLocation" location="enemy_cache01" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_cache02" player_type="campaign_team" amount="1" /><condition type="UnitInLocation" location="enemy_cache03" player_type="campaign_team" amount="1" /></if_any><event name="enemy_cache" /></trigger><trigger name="narcom" interval="0.8" preserved="false"><condition type="UnitInLocation" location="narcom" player_type="campaign_team" amount="1" /><event name="narcom" /></trigger><event name="narcom"><element type="Actor" actor="m01_intel" start_time="1.5" /><element type="StopTrigger" name="narcom" /></event></mission_script>

here is the code

using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace TestXml
{
    public partial class test : Form
    {
        public test()
        {
            InitializeComponent();
        }

        private string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
 
        private void test_Load(object sender, EventArgs e)
        {
            textBox1.Text = path + @"\Graw Mission Script\mission.xml";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(path + @"\Graw Mission Script\mission.xml");

            try
            {
                TreeView treeView = new TreeView();
                treeView1.Nodes.Clear();
                treeView1.Nodes.Add(new TreeNode(xDoc.DocumentElement.Name));
                AddNode(xDoc.DocumentElement, treeView1.Nodes[0]);
                treeView1.CollapseAll();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
 
        public void AddNode(XmlNode inXmlNode, TreeNode inTreeNode)
        {
            XmlAttributeCollection atts = inXmlNode.Attributes;
            TreeNode tNode = new TreeNode("Attributes");
            if (atts.Count != 0)
            {
                foreach (XmlAttribute att in atts)
                {
                    tNode.Nodes.Add(new TreeNode(att.Name));
                }

                inTreeNode.Nodes.Add(tNode);
            }
 
            foreach (XmlNode xNode in inXmlNode.ChildNodes)
            {
                switch (xNode.NodeType)
                {
                    case XmlNodeType.Element:
                        tNode = new TreeNode("<" + xNode.Name + ">");
                        AddNode(xNode, tNode);
                        break;
                    case XmlNodeType.Comment:
                        tNode = new TreeNode("comment = " + xNode.Value);
                        break;
                    case XmlNodeType.CDATA:
                        tNode = new TreeNode("#cdata " + xNode.Value);
                        break;
                    default:
                        throw new Exception("Unexpected NodeType: " + xNode.NodeType.ToString());
                }

                inTreeNode.Nodes.Add(tNode);
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            listView1.Columns.Clear();
            TreeView tv = (TreeView)sender;

            if (tv.SelectedNode.Nodes.Count > 1)
            {
                foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
                {
                    listView1.Columns.Add(tvNode.Text);
                    //listView1.Items.Add(att.Value);
                }
            }
        }
    }
}



What do I have to do to get the values of the attributes under there name in the list view?




Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>