static void Main() { Application.Run(new Form1()); } private System.Windows.Forms.GroupBox grpbox; XPathDocument dom; XmlDocument doc; XPathNavigator nav; XPathExpression expr; XPathNodeIterator iterator; int cnt=0; Label lbl; TextBox txt; OpenFileDialog dlg; TreeNode newTreeNode,rootnode,parentnode; string text; int i; //int cnt = e.Node.GetNodeCount(false); //string filename; private void Form1_Load(object sender, System.EventArgs e) { //label1.Text = "File Path"; //label1.SetBounds(8, 8, 50, 20); //filename = Application.StartupPath + "\\Sample.xml"; //textBox1.Text= filename; //textBox1.SetBounds(64, 8, 256, 20); button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); //dom = new XPathDocument(dlg.FileName); } // it will acess the xml file into treeview private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTree
samidhas
Posts
-
want a help in the code...... [modified] -
how to add a now treenode in the following code?if i want to insert a now node name an value , by entering it in the text box, and after cliking on button the node should be add to the tree view -------------------------------------------------------------------- private void Form1_Load(object sender, System.EventArgs e) { button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } --------------------------------------------------------------------------
-
i want to insert a new node regarding this code.but insert is not working..i just want to insert a new node in the treeview and xml file both , where i can insert name and values from textbox.... will u help in for code?
-
i want to insert a new node regarding this code.but insert is not working..no i am not getting the logic how to do it? an confustion in a code....
-
i want to insert a new node regarding this code.but insert is not working..private System.Windows.Forms.GroupBox grpbox; XPathDocument dom; XmlDocument doc; XPathNavigator nav; XPathExpression expr; XPathNodeIterator iterator; int cnt=0; Label lbl; TextBox txt; OpenFileDialog dlg; TreeNode newTreeNode; //int cnt = e.Node.GetNodeCount(false); //string filename; private void Form1_Load(object sender, System.EventArgs e) { //label1.Text = "File Path"; //label1.SetBounds(8, 8, 50, 20); //filename = Application.StartupPath + "\\Sample.xml"; //textBox1.Text= filename; //textBox1.SetBounds(64, 8, 256, 20); button1.Text = "Populate the TreeView with XML"; button1.SetBounds(8, 20, 200, 20); treeXml.Height = 600; treeXml.Width = 400; grpbox = new GroupBox(); grpbox.Height = 600; grpbox.Width = 400; grpbox.SetBounds(500, 2, 700, 600); grpbox.Visible = true; grpbox.Dock.Equals(Right); grpbox.Show(); this.Controls.Add(grpbox); //dom = new XPathDocument(dlg.FileName); } private void ConvertXmlNodeToTreeNode(XmlNode xmlNode, TreeNodeCollection treeNodes) { TreeNode newTreeNode = treeNodes.Add(xmlNode.Name); switch (xmlNode.NodeType) { case XmlNodeType.ProcessingInstruction: case XmlNodeType.XmlDeclaration: newTreeNode.Text = "<?" + xmlNode.Name + " " + xmlNode.Value + "?>"; break; case XmlNodeType.Element: if (xmlNode.Name.ToLower().Equals("node") == true) { newTreeNode.Text = "<" + xmlNode.Attributes["label"].Value.ToString() + ">"; } else newTreeNode.Text = "<" + xmlNode.Name + ">"; break; case XmlNodeType.Attribute: newTreeNode.Text = xmlNode.Name; // newTreeNode.Text = "ATTRIBUTE: " + xmlNode.Name; break; case XmlNodeType.Text: case XmlNodeType.CDATA: newTreeNode.Text = xmlNode.Value; break; case XmlNodeType.Comment: newTreeNode.Text = "<!--" + xmlNode.Value + "-->"; break; } if (xmlNode.Attributes != null) { foreach (XmlAttribute attribute in xmlNode.Attributes) { ConvertXmlNodeToTreeNode(attribute, newTreeNode.Nodes); } } foreach (XmlNode childNode in xmlNode.ChildNodes) { ConvertXmlNodeToTreeNode(childNode, newTreeNode.Nodes); } } private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { cnt = e.No
-
how to insert a new node in a tree view programatically?i have textbox in which i can fill the values which should be updated into the treenode...?
-
how to read filename?thank a lot
-
how to read filename?hi, if i am using folloing code to open a perticular xml file, OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Open XML File"; dlg.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*" ; if (dlg.ShowDialog() == DialogResult.OK) { doc.Load(dlg.OpenFile()); } and now if i want to read a file name in the xmltextreader , how can i read it?
-
how to pass a value from an event to on button click?oh that was simple yar....... thanks....
-
how to pass a value from an event to on button click?its not working bcoz i am using e.node which can be only possible in the treeview event not in the main class ..... am i right, plz guide me
-
how to pass a value from an event to on button click?hi friends , i want to pass a cnt value which is used in event to button click... how can i do it? -------------------------------------------------------------- private void treeXml_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e,e) { int cnt = e.Node.GetNodeCount(false); grpbox.Controls.Clear(); for (int i = 0; i < cnt; i++) { Label lbl = new Label(); TextBox txt = new TextBox(); //PictureBox img = new PictureBox(); lbl.Text = e.Node.Text; lbl.Left = 200; lbl.Top = 200 * i; txt.Left = 250; txt.Top = 200 * i; //img.left=300; //img.top=200 * i; lbl.Show(); txt.Show(); grpbox.Controls.Add(txt); grpbox.Controls.Add(lbl); //grpbox.Controls.Add(img); } } private void button2_Click(object sender, System.EventArgs e) { }
-
xml and lable; if xml file is in this format then how can i get a lable name as a "holiday destinations on tree node? if xml is in the form < text> themn tex will be a lable of tree node.in this format. how can i get it?
-
how to display the tree nodes and its atrributes in the list format in multiline textboxhi, i have access a xml file in tree view, now i want to do .......... when i will click on any node on the tree view the all attributes of that tree node like ,pic, sound, text etc should be seen in another textbox(multiline). i have used trewview for this... how can i do this?
-
how can i search a node in tree view?its urgent plz help meeeeeeeee
-
how can i acessthe xml file in c#?plzzzzzz explain through code , i dint get you thanks
-
how can i acessthe xml file in c#?i want to see a whole xml file in the richtext box. how can i see it or access it?
-
how can i search a node in tree view?how can i programatically search node in the treeview? and if i am accessing xml file in treeview, then how can i search the node in xml file too?
-
how can i access the xml file in the in richtextbox in c#.net?how can i access the xml file in the in richtextbox in c#.net?
-
how to save ?if i am accessing a xml file in c#, tree view. an if i delet the node from tree view an save it in original xml file, how can i save it? plzzzzzzz help me its urgunt.........
-
how can i add a new node in treeview programatically ? and save changes?how can i add a new node in treeview for an xml backend file? and save it?