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. Visual Basic
  4. Renaming a TreeNode and updating an XML file

Renaming a TreeNode and updating an XML file

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structuresxmlhelp
11 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.
  • C cwayman

    Hey, I have a treeview in my vb.net application. when i change the name of my treenode i am trying to reflect the change in my xml document and then repopulate the tree. Data To be Updated I can populate tree view, and rename the tree node but am unable to reflect the change in the xml Any help would be greatly appreciated i have tried looking at examples but and unable to get anywhere. thanks for any help in advance

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #2

    How is your Treeview bound to the XML? Is it through a DataSet or is the TreeView just loading it from the .XML file directly? The only way you can do something like this is if your Treeview is bound to a DataSet version of the XML file. When the data is changed in the Treeview, the DataSet can be updated. When the changes are complete, the DataSet can export back to an XML file. The Treeview control CANNOT do this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

    C 1 Reply Last reply
    0
    • D Dave Kreskowiak

      How is your Treeview bound to the XML? Is it through a DataSet or is the TreeView just loading it from the .XML file directly? The only way you can do something like this is if your Treeview is bound to a DataSet version of the XML file. When the data is changed in the Treeview, the DataSet can be updated. When the changes are complete, the DataSet can export back to an XML file. The Treeview control CANNOT do this. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      C Offline
      C Offline
      cwayman
      wrote on last edited by
      #3

      Hey, I populate my tree using a recursive function to load hte xml file, and can add nodes to the tree which update the xml file using MSXML. Can i use MSXML to update the data between tags in the XML file: Data To be Updated (the tree node names) based on the selected tree node being renamed using the AfterLabelEdit command? Thanks for the help :) Chris

      D 1 Reply Last reply
      0
      • C cwayman

        Hey, I populate my tree using a recursive function to load hte xml file, and can add nodes to the tree which update the xml file using MSXML. Can i use MSXML to update the data between tags in the XML file: Data To be Updated (the tree node names) based on the selected tree node being renamed using the AfterLabelEdit command? Thanks for the help :) Chris

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #4

        Well, since the TreeView control doesn't support Data Binding, you'll either have to add that support by creating a custom TreeView control or use a similar procedure to write the data back out that you used to get it into the TreeView. You'll have to do some extra research on these methods to see what's going to work the best for your situation and requirements. You might want to take a look at Extending the TreeView Control[^] on MSDN for a how-to on adding Data Binding. When you rename a node in the Tree, the TreeView will fire a couple of events. You use the source data to find the appropriate node in the DataSet and update the data in the DataSet. Now, when your done, the DataSet object can write the resulting XML file back out for you. You won't have to iterate through the nodes and write eash one out by hand. That's why I highly suggest you use a DataSet object for your Tree data source. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        C 1 Reply Last reply
        0
        • D Dave Kreskowiak

          Well, since the TreeView control doesn't support Data Binding, you'll either have to add that support by creating a custom TreeView control or use a similar procedure to write the data back out that you used to get it into the TreeView. You'll have to do some extra research on these methods to see what's going to work the best for your situation and requirements. You might want to take a look at Extending the TreeView Control[^] on MSDN for a how-to on adding Data Binding. When you rename a node in the Tree, the TreeView will fire a couple of events. You use the source data to find the appropriate node in the DataSet and update the data in the DataSet. Now, when your done, the DataSet object can write the resulting XML file back out for you. You won't have to iterate through the nodes and write eash one out by hand. That's why I highly suggest you use a DataSet object for your Tree data source. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          C Offline
          C Offline
          cwayman
          wrote on last edited by
          #5

          Thanks for your input, appreciate it. I have managed to load the xml file in to a dataset before, but was unable to make the treeview use this dataset. I will read that article and let you know how i get on. Thanks again Chris

          C 1 Reply Last reply
          0
          • C cwayman

            Thanks for your input, appreciate it. I have managed to load the xml file in to a dataset before, but was unable to make the treeview use this dataset. I will read that article and let you know how i get on. Thanks again Chris

            C Offline
            C Offline
            cwayman
            wrote on last edited by
            #6

            Hey Dave, I have written a function that can update the xml file using a DataSet. My problem is I call this function in the AfterLabelEdit method and it runs. But it updates the old name with the old name! as i cannot catch the new name that is typed in to the selected treenode until the AfterLabelEdit method as finished. Do you have any suggestions of how to get the newly type name so when enter is pressed and the AfterLabelEdit method is run the new name can be used to update the old one using the update dataset function. Thanks you for your help Chris

            D 1 Reply Last reply
            0
            • C cwayman

              Hey Dave, I have written a function that can update the xml file using a DataSet. My problem is I call this function in the AfterLabelEdit method and it runs. But it updates the old name with the old name! as i cannot catch the new name that is typed in to the selected treenode until the AfterLabelEdit method as finished. Do you have any suggestions of how to get the newly type name so when enter is pressed and the AfterLabelEdit method is run the new name can be used to update the old one using the update dataset function. Thanks you for your help Chris

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #7

              What's the code in the event handler? Are you using the .Text property of the e.Node object that's passed to the handler? You will get the Node that was edited in the e.Node object AND you will get the new label text in the e.Label object. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              C 1 Reply Last reply
              0
              • D Dave Kreskowiak

                What's the code in the event handler? Are you using the .Text property of the e.Node object that's passed to the handler? You will get the Node that was edited in the e.Node object AND you will get the new label text in the e.Label object. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                C Offline
                C Offline
                cwayman
                wrote on last edited by
                #8

                Hey, Cheers again for the help, i have used a timer and made the AfterSelectEvent fire that. But will be changing my treenode to use a real dir structure soon, so i will keep that in mind thankyou. Another question is that i am now using DSOFile to load MS Office file properties in to the form when the file node of my tree is double clicked. This works and loads the file properties in to the form first time the node is double clicked, but if you try to go back to that file an error occurs saying that it cannot load the file properties because the file is open. Is there anyway to close the file as soon as the properties have been retrieved? Thank you for all your help Chris

                D 1 Reply Last reply
                0
                • C cwayman

                  Hey, Cheers again for the help, i have used a timer and made the AfterSelectEvent fire that. But will be changing my treenode to use a real dir structure soon, so i will keep that in mind thankyou. Another question is that i am now using DSOFile to load MS Office file properties in to the form when the file node of my tree is double clicked. This works and loads the file properties in to the form first time the node is double clicked, but if you try to go back to that file an error occurs saying that it cannot load the file properties because the file is open. Is there anyway to close the file as soon as the properties have been retrieved? Thank you for all your help Chris

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #9

                  You can force the release of the underlying COM object by using Marshal.ReleaseComObject() on the instance of the DSO object you created. Try this:

                  Imports System.Runtime.Interop
                  .
                  .
                  .
                  ' I'm assuming you're using the PropertyReadClass...
                  Dim dso As New DSOleFile.PropertyReaderClass
                  '
                  ' Do whatever you need to with the object here...
                  '
                  ' Now, release the unmanaged object and it's underlying resources.
                  Marshal.ReleaseComObject(dso)
                  ' Drop our managed reference to the object.
                  dso = Nothing
                  .
                  .
                  .

                  And let the garbage collector do the rest... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  C 1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    You can force the release of the underlying COM object by using Marshal.ReleaseComObject() on the instance of the DSO object you created. Try this:

                    Imports System.Runtime.Interop
                    .
                    .
                    .
                    ' I'm assuming you're using the PropertyReadClass...
                    Dim dso As New DSOleFile.PropertyReaderClass
                    '
                    ' Do whatever you need to with the object here...
                    '
                    ' Now, release the unmanaged object and it's underlying resources.
                    Marshal.ReleaseComObject(dso)
                    ' Drop our managed reference to the object.
                    dso = Nothing
                    .
                    .
                    .

                    And let the garbage collector do the rest... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                    C Offline
                    C Offline
                    cwayman
                    wrote on last edited by
                    #10

                    Hey, Thanks for the reply. I have tried using the Marshal.ReleaseComObject but it does not seem to close the file, giving the error 'The file is open and cannot be read'. I have used hte import of InteropServices too. my code is: 'DSO Properties Dim oDsoPropReader As DSOleFile.PropertyReader = New DSOleFile.PropertyReaderClass Dim oDsoFileProp As DSOleFile.DocumentProperties oDsoFileProp = oDsoPropReader.GetDocumentProperties(strFullPath) '<-- This line causes the error tbAuthor.Text = oDsoFileProp.Author tbFormat.Text = oDsoFileProp.AppName lblDateCreated.Text = oDsoFileProp.DateCreated lblDateModfied.Text = oDsoFileProp.DateLastSaved Marshal.ReleaseComObject(oDsoPropReader) oDsoFileProp = Nothing oDsoPropReader = Nothing Is my code wrong?, this help is really appreciated. Chris

                    C 1 Reply Last reply
                    0
                    • C cwayman

                      Hey, Thanks for the reply. I have tried using the Marshal.ReleaseComObject but it does not seem to close the file, giving the error 'The file is open and cannot be read'. I have used hte import of InteropServices too. my code is: 'DSO Properties Dim oDsoPropReader As DSOleFile.PropertyReader = New DSOleFile.PropertyReaderClass Dim oDsoFileProp As DSOleFile.DocumentProperties oDsoFileProp = oDsoPropReader.GetDocumentProperties(strFullPath) '<-- This line causes the error tbAuthor.Text = oDsoFileProp.Author tbFormat.Text = oDsoFileProp.AppName lblDateCreated.Text = oDsoFileProp.DateCreated lblDateModfied.Text = oDsoFileProp.DateLastSaved Marshal.ReleaseComObject(oDsoPropReader) oDsoFileProp = Nothing oDsoPropReader = Nothing Is my code wrong?, this help is really appreciated. Chris

                      C Offline
                      C Offline
                      cwayman
                      wrote on last edited by
                      #11

                      I have solved hte problem i also released the DocumentProperties as well as the reader, thanks for all your help Dave. Chris

                      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