Click here to Skip to main content
15,891,633 members
Home / Discussions / C#
   

C#

 
AnswerRe: richtextbox Pin
Raj Mouli28-Feb-14 22:00
Raj Mouli28-Feb-14 22:00 
QuestionYou can define columns for a temporary DataTable? Pin
Souza-1063377928-Feb-14 8:34
Souza-1063377928-Feb-14 8:34 
AnswerRe: You can define columns for a temporary DataTable? Pin
Mycroft Holmes28-Feb-14 12:59
professionalMycroft Holmes28-Feb-14 12:59 
QuestionC # if statement (parameter read form sql Server DB) Pin
Member 1063374328-Feb-14 8:16
Member 1063374328-Feb-14 8:16 
AnswerRe: C # if statement (parameter read form sql Server DB) Pin
Richard Deeming28-Feb-14 8:27
mveRichard Deeming28-Feb-14 8:27 
GeneralRe: C # if statement (parameter read form sql Server DB) Pin
Member 1063374328-Feb-14 8:36
Member 1063374328-Feb-14 8:36 
GeneralRe: C # if statement (parameter read form sql Server DB) Pin
Member 104046945-Mar-14 21:29
Member 104046945-Mar-14 21:29 
AnswerRe: C # if statement (parameter read form sql Server DB) Pin
ZurdoDev28-Feb-14 10:56
professionalZurdoDev28-Feb-14 10:56 
QuestionMessage Closed Pin
27-Feb-14 20:31
Member 1063210727-Feb-14 20:31 
AnswerRe: plz Pin
V.27-Feb-14 20:46
professionalV.27-Feb-14 20:46 
AnswerRe: plz Pin
Bernhard Hiller27-Feb-14 20:48
Bernhard Hiller27-Feb-14 20:48 
AnswerRe: plz Pin
ScottM127-Feb-14 20:53
ScottM127-Feb-14 20:53 
AnswerRe: plz Pin
GuyThiebaut27-Feb-14 22:01
professionalGuyThiebaut27-Feb-14 22:01 
GeneralRe: plz Pin
Richard MacCutchan27-Feb-14 22:14
mveRichard MacCutchan27-Feb-14 22:14 
AnswerRe: plz PinPopular
Pete O'Hanlon28-Feb-14 0:29
mvePete O'Hanlon28-Feb-14 0:29 
GeneralRe: plz Pin
Wayne Gaylard28-Feb-14 1:59
professionalWayne Gaylard28-Feb-14 1:59 
AnswerRe: plz Pin
Ennis Ray Lynch, Jr.28-Feb-14 5:15
Ennis Ray Lynch, Jr.28-Feb-14 5:15 
QuestionHow to click on a node in treeview and display and edit data in listview Pin
daddy35627-Feb-14 18:14
daddy35627-Feb-14 18:14 
AnswerRe: How to load an xml into a treeview then when clicked on an item shows in listview Pin
BillWoodruff27-Feb-14 21:51
professionalBillWoodruff27-Feb-14 21:51 
AnswerRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff1-Mar-14 14:13
professionalBillWoodruff1-Mar-14 14:13 
AnswerRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff8-Mar-14 4:04
professionalBillWoodruff8-Mar-14 4:04 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
daddy3569-Mar-14 12:04
daddy3569-Mar-14 12:04 
Well Bill,
I tried your code, I just don't think I'm including it right in my code.

I managed to get the node text listed in columns and their values
listed below each node.
Now I need to figure out how to edit the value in list view and then save them, also apply an image list to the tree view with
different images for nodes.

Here is what I have:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
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);
        XmlDocument xDoc = new XmlDocument();
        List<string> values = new List<string>();

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

        private void button1_Click(object sender, EventArgs e)
        {
            xDoc.Load(textBox1.Text);
            StreamReader sr = new StreamReader(path + @"\Graw Mission Script\mission.xml");
            textBox2.Text = sr.ReadToEnd();

            try
            {
                treeView1.Nodes.Clear();
                treeView1.Nodes.Add(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(att.Name).Nodes.Add(att.Value);
                }

                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("<!--" + 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.Clear();
            TreeView tv = (TreeView)sender;

            if (tv.SelectedNode.Text != "Attributes")
            {
                return;
            }
            
            if (tv.SelectedNode.Parent == null || tv.SelectedNode.GetNodeCount(false) == 0) return;
            {
                foreach (TreeNode tvNode in tv.SelectedNode.Nodes)
                {
                    listView1.Columns.Add(tvNode.Text);
                    values.Add(tvNode.Nodes[0].Text);
                }

                ListViewItem item = listView1.Items.Add(values[0]);
                values.RemoveAt(0);

                if (values.Count > 0)
                {
                    item.SubItems.AddRange(values.ToArray());
                }
            }
        }
     
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // I haven't a clue ????
        }
    }
}


any help with that would be greatly appreciated.

modified 9-Mar-14 18:16pm.

GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff9-Mar-14 21:04
professionalBillWoodruff9-Mar-14 21:04 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
daddy3569-Mar-14 21:19
daddy3569-Mar-14 21:19 
GeneralRe: How to click on a node in treeview and display and edit data in listview Pin
BillWoodruff9-Mar-14 21:41
professionalBillWoodruff9-Mar-14 21:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.