Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with code after ShowDialog and XML add node

Problem with code after ShowDialog and XML add node

Scheduled Pinned Locked Moved C#
xmlhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rapier503
    wrote on last edited by
    #1

    Hello, The code below I have:- static string filename; static XmlDocument xmlDoc; and open the XML file in the Form Load. If I remove the :- if (testDialog.ShowDialog() == DialogResult.OK) Line the XML addnode code works OK. With the ShowDialog() line in the XML node add code does not work. Why? Also is there something I can check (return code?) to make sure each part of the add node lines of code has worked? void Button1Click(object sender, EventArgs e) { NewForm testDialog = new NewForm(); if (testDialog.ShowDialog() == DialogResult.OK) { MessageBox.Show("Here"); XmlNode root = xmlDoc.DocumentElement; XmlElement childNode = xmlDoc.CreateElement("ABCD"); XmlElement childNode2 =xmlDoc.CreateElement("Name"); XmlText textNode = xmlDoc.CreateTextNode("ABCD"); root.AppendChild(childNode); childNode.AppendChild(childNode2); childNode2.SetAttribute("Name", "Name"); childNode2.AppendChild(textNode); xmlDoc.Save(filename); MessageBox.Show("Here2"); } testDialog.Dispose(); } Thanks is Advance, Rapier

    A 1 Reply Last reply
    0
    • R Rapier503

      Hello, The code below I have:- static string filename; static XmlDocument xmlDoc; and open the XML file in the Form Load. If I remove the :- if (testDialog.ShowDialog() == DialogResult.OK) Line the XML addnode code works OK. With the ShowDialog() line in the XML node add code does not work. Why? Also is there something I can check (return code?) to make sure each part of the add node lines of code has worked? void Button1Click(object sender, EventArgs e) { NewForm testDialog = new NewForm(); if (testDialog.ShowDialog() == DialogResult.OK) { MessageBox.Show("Here"); XmlNode root = xmlDoc.DocumentElement; XmlElement childNode = xmlDoc.CreateElement("ABCD"); XmlElement childNode2 =xmlDoc.CreateElement("Name"); XmlText textNode = xmlDoc.CreateTextNode("ABCD"); root.AppendChild(childNode); childNode.AppendChild(childNode2); childNode2.SetAttribute("Name", "Name"); childNode2.AppendChild(textNode); xmlDoc.Save(filename); MessageBox.Show("Here2"); } testDialog.Dispose(); } Thanks is Advance, Rapier

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      Does your NewForm return a DialogResult anywhere in your code? Supposing that the NewForm form has been created by you.

      There are 10 kinds of people: those who understand binary and those who don't

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups